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: How can I use a formatted string as a variable name?
Replies: 1   Last Post: Jan 9, 2014 1:41 PM

Advanced Search

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

Posts: 3,894
Registered: 12/7/04
Re: How can I use a formatted string as a variable name?
Posted: Jan 9, 2014 1:41 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Friday, January 10, 2014 7:29:08 AM UTC+13, Nick Kitchen wrote:
> I'm a pretty amateur Matlab user but I'm having some trouble assigning a simple row vector to a formatted string containing a loop count. The idea is that by the end of the loop I will have a set of variables (scores); 1 for each of the times the loop ran.
>
>
>
> I have tried the following where 'LoopNo' is the variable representing the loop count and 'Player' and 'Comp' representing the scores of the Player and Computer respectively...
>
>
>
> sprintf('Scores%d', LoopNo) = [Player, Comp]
>
>
>
> But get the following error message
>
>
>
> ??? Subscripted assignment dimension mismatch.
>
>
>
> I'm fairly sure there's a simple solution but have been pretty stuck with it as a definite Matlab beginner, if anyone could help I would greatly appreciate it,
>
>
>
> Thanks,
>
>
>
> Nick


Don't do this!
You will get yourself into all sorts of a muddle.
Use a matrix instead:
scores=zeros(nrun,2); % Allocate storage

Then inside the loop:
scores(LoopNo,:)=[Player Comp];



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.