Thread Subject: change matrix name in iteration

Subject: change matrix name in iteration

From: Abdul Rauf Anwar

Date: 15 Apr, 2011 11:15:22

Message: 1 of 4

Hi
this would be stupid but i cant find a way to rename a matrix during loop iterations
see
eval(['y_' num2str(counter) '=' x(:,i:i+9) ])
in this statement i want 'y' to be matrix and since this very line will run 10 times so at the end i should have 10 different matrices as y_1, y_2, ...,y_10
but i suppose this line works only as singular value
i would be obliged if someone helps me out of this
Thanks

Subject: change matrix name in iteration

From: Nasser M. Abbasi

Date: 15 Apr, 2011 11:29:39

Message: 2 of 4

On 4/15/2011 4:15 AM, Abdul Rauf Anwar wrote:
> Hi
> this would be stupid but i cant find a way to rename a matrix during loop iterations
> see
> eval(['y_' num2str(counter) '=' x(:,i:i+9) ])
> in this statement i want 'y' to be matrix and since this very line will
> run 10 times so at the end i should have 10 different matrices as y_1, y_2, ...,y_10
> but i suppose this line works only as singular value
> i would be obliged if someone helps me out of this
> Thanks

I do not think the above is a good way to do things.

If you want at the end 10 different matrices, then
make a 3D matrix, and use the index to locate
your 10 matrices.

This allocates 10 matrix, each of size 5 by 5:

  A=zeros(5,5,10);

Simply then do

    c = A(:,:,i)

to obtain the 'ith' matrix.

It is important to first sit and think carfully about your data
structure.

Remember what Wirth said: algorithms + data structures - programs

--Nasser

Subject: change matrix name in iteration

From: Nasser M. Abbasi

Date: 15 Apr, 2011 11:30:43

Message: 3 of 4

On 4/15/2011 4:29 AM, Nasser M. Abbasi wrote:

>
> Remember what Wirth said: algorithms + data structures - programs
>

opps, "-" --> "=" ofcourse

--Nasser

Subject: change matrix name in iteration

From: dpb

Date: 15 Apr, 2011 12:02:03

Message: 4 of 4

On 4/15/2011 6:15 AM, Abdul Rauf Anwar wrote:
> Hi
> this would be stupid but i cant find a way to rename a matrix during
> loop iterations
...

That's good...you don't want to do that, anyway. For why and how to
accomplish the task, see 4.6 in the Matlab FAQ Wiki...

<http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F>

--

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com