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 ]
Kevin Ellis

Posts: 53
Registered: 11/29/10
Re: Help using textscan or sscanf
Posted: Jan 20, 2013 1:48 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

dpb <none@non.net> wrote in message <kdf43h$5pl$1@speranza.aioe.org>...
> 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.
>
> --


I feel bad. I knew this was a challenging problem, but I'm impressed. The solution you came up with significantly reduces the runtime. One thing I should mention is that I have had to copy the section of code 12 times for each month of the year. I call the dataset using datenum for each month ('001' for October all the way to '012' for September). I append that number onto the end of the number that your code made above. So you were able to accomplish the task in much fewer lines of code which is very impressive. Who knew it could be so simple. Too bad there isn't a built-in function in MatLab where you can just read strings right to left. That would make things much easier. Again I appreciate the dedication to the task. I only recently started using datasets because the data I have is so large that cell arrays and structures become difficult to manage. The dataset is a perfect medium.

Kevin



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.