Date: Jan 16, 2013 1:18 PM
Author: dpb
Subject: Re: Help using textscan or sscanf

On 1/16/2013 11:30 AM, Kevin Ellis wrote:
> Hello,
>
> My problem is very simple, but I cannot find an efficient way to
> accomplish it. Here is an excerpt of my array (which is one column of a
> dataset):
>
> 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.
>
> So my problem is difficult in that I need to use sscanf to find the last
> 9 digits of the account number...


Nope...

>> s
=strvcat('154045001','926665001','615017','1976936151','801700','4506702001');
>> [repmat('4412',6,1) s(:,end-9:end)]
ans =
4412154045001
4412926665001
4412615017
44121976936151
4412801700
44124506702001
>>

I'd suggest in the end it _might_ be better to "normalize" the account
no's by prepending zeros for the short strings. Then they would sort,
etc., more nearly normally (for at least one definition of "normal",
anyway).

--