Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Help using textscan or sscanf
Replies: 21   Last Post: Jan 23, 2013 4:02 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,220
Registered: 6/7/07
Re: Help using textscan or sscanf
Posted: Jan 19, 2013 4:10 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 1/16/2013 11:30 AM, Kevin Ellis wrote:
...

> Subset001.AccountNumber(1:6,:)
>
> ans =
> '154045001'
> '926665001'
> '615017'
> '1976936151'
> '801700'
> '4506702001'
>
> I am trying to create a new account number in the form of a string. I
> need to append '4412' to the the last 9 digits of the above account
> numbers. So for the results is:
>
> '4412154045001'
> '4412926665001' - Account Numbers have 9 digits so this is easy
> '4412615017' - Only has 6 digits so take the whole account number
> '4412976936151' - Has 10 digits so drop first and append to '4412'
> etc.

...

I only got access to Statistics Toolbox within last couple of weeks so
have virtually no proficiency w/ the DATASET object but...you can do
essentially my previous solution (which was correct except I forgot and
used (end:-9:end) instead of (end-8:end) for the length subscript to get
9 characters to append) from a dataset as--

>> a={'154045001' '926665001' '615017' '1976936151' '801700'
'4506702001'}';
>> D=dataset({a,'acct'});
>> c=char(D.acct);
>> D.newaccdt=cellstr([repmat('4412',6,1) c(:,end-8:end)])

D =
acct newaccdt
'154045001' '441254045001'
'926665001' '441226665001'
'615017' '441215017'
'1976936151' '4412976936151'
'801700' '441201700'
'4506702001' '4412506702001'
>>

I'm pretty sure if you worked at it and w/ more proficiency in the
dataset methods you could probably do it w/o the temporary explicit
array c above.

But clearly you don't need two subsets and sscanf() and all the
rigamarole you're presently going thru...

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.