Search All of the Math Forum:

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

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

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Kevin Ellis Posts: 62 Registered: 11/29/10
Help using textscan or sscanf
Posted: Jan 16, 2013 12:30 PM
 Plain Text Reply

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 (even if it has less or more) and then use strcat to append '4412' to the beginning. A few poor attempts:

strcat('4412',sscanf(Subset001.AccountNumber{6},'%*c%9c',1))
strcat('4412',sscanf(Subset001.AccountNumber{6},'%s,[1,9]))

These obviously do not work and I can seem to find a metacharacter in the sscanf documentation for indicating a way to start at the end of the string count back 8 characters and return the result. Does it sscanf always have to read left to right? Any help would be much appreciated. Thanks.

Kevin Ellis

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

© The Math Forum at NCTM 1994-2017. All Rights Reserved.