Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: How can I use a formatted string as a variable name?
Posted:
Jan 9, 2014 1:41 PM


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



