Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 dpb Posts: 9,850 Registered: 6/7/07
Re: Help using textscan or sscanf
Posted: Jan 19, 2013 4:44 PM

On 1/19/2013 3:10 PM, dpb wrote:
...

> >> 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)])

...

Oooops....I forgot about the length being augmented to that of the longest.

Need to right-justify, then pick the last 9 char's and then concatenate...

>> c=strjust(char(D.acct));
>> D.newaccdt=cellstr( ...

[repmat('4412',6,1) strjust(c(:,end-8:end),'left')])
D =
acct newaccdt
'154045001' '4412154045001'
'926665001' '4412926665001'
'615017' '4412615017'
'1976936151' '4412976936151'
'801700' '4412801700'
'4506702001' '4412506702001'
>>

OK, now we got the right last N (=9) characters.

--

Date Subject Author
1/16/13 Kevin Ellis
1/16/13 dpb
1/16/13 Kevin Ellis
1/16/13 dpb
1/16/13 Kevin Ellis
1/16/13 dpb
1/17/13 dpb
1/17/13 dpb
1/19/13 dpb
1/19/13 dpb
1/19/13 dpb
1/20/13 Kevin Ellis
1/20/13 dpb
1/20/13 james bejon
1/20/13 Kevin Ellis
1/20/13 james bejon
1/21/13 james bejon
1/22/13 Kevin Ellis
1/22/13 james bejon
1/23/13 Doug Schwarz
1/23/13 james bejon