Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
problem whit loop

Subject: problem whit loop

From: bahram

Date: 14 Aug, 2010 13:35:04

Message: 1 of 5

Hi everybody
i am fresh in matlab ,i have some matrix and i want to put all off them in one matrix W
it means that convert each matrix whit reshape command and put each of converted matrix in a row of new matrix
it means that matrix w1 change whit reshape and convert to a vector and put it in new matrix as a first row and so on

ex:
 w1=[1 2 3; 4 5 6; 7 8 9]
w2= [2 3 4 ; 6 7 8; 1 4 5]
.
.
.
w6=[1 4 5; 1 4 8 ; 2 3 4]


reshape(w1,9,1) ===> put it for first row of new matrix of W
reshape (w2,9,1) ====> put it for secend row of new matrix of W
.
.
.
reshape(w6,9,1)===.put it for sixth row of new matrix of W
W=1 2 3 4 5 6 7 8 9
     2 3 4 6 7 8 1 4 5
    ...

 how can make a loop whit for end
how shod define w1 to w6

for wi=1:6 or ........

end
plz help me

Subject: problem whit loop

From: Ross W

Date: 19 Aug, 2010 11:05:04

Message: 2 of 5

"bahram " <b3hrad11@yahoo.com> wrote in message <i46628$edi$1@fred.mathworks.com>...
> Hi everybody
> i am fresh in matlab ,i have some matrix and i want to put all off them in one matrix W
> it means that convert each matrix whit reshape command and put each of converted matrix in a row of new matrix
> it means that matrix w1 change whit reshape and convert to a vector and put it in new matrix as a first row and so on
>
> ex:
> w1=[1 2 3; 4 5 6; 7 8 9]
> w2= [2 3 4 ; 6 7 8; 1 4 5]
> .
> .
> .
> w6=[1 4 5; 1 4 8 ; 2 3 4]
>
>
> reshape(w1,9,1) ===> put it for first row of new matrix of W
> reshape (w2,9,1) ====> put it for secend row of new matrix of W
> .
> .
> .
> reshape(w6,9,1)===.put it for sixth row of new matrix of W
> W=1 2 3 4 5 6 7 8 9
> 2 3 4 6 7 8 1 4 5
> ...
>
> how can make a loop whit for end
> how shod define w1 to w6
>
> for wi=1:6 or ........
>
> end
> plz help me

hi
you can do this using eval, but it's not a good idea.
you might want to reconsider using w1 w2 w3 etc as variable names. do you really need to?
see http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

ross

Subject: problem whit loop

From: b3hrad

Date: 19 Nov, 2010 14:02:03

Message: 3 of 5

"Ross W" <rosswoodskiwi@hotmail.com> wrote in message <i4j350$frf$1@fred.mathworks.com>...
> "bahram " <b3hrad11@yahoo.com> wrote in message <i46628$edi$1@fred.mathworks.com>...
> > Hi everybody
> > i am fresh in matlab ,i have some matrix and i want to put all off them in one matrix W
> > it means that convert each matrix whit reshape command and put each of converted matrix in a row of new matrix
> > it means that matrix w1 change whit reshape and convert to a vector and put it in new matrix as a first row and so on
> >
> > ex:
> > w1=[1 2 3; 4 5 6; 7 8 9]
> > w2= [2 3 4 ; 6 7 8; 1 4 5]
> > .
> > .
> > .
> > w6=[1 4 5; 1 4 8 ; 2 3 4]
> >
> >
> > reshape(w1,9,1) ===> put it for first row of new matrix of W
> > reshape (w2,9,1) ====> put it for secend row of new matrix of W
> > .
> > .
> > .
> > reshape(w6,9,1)===.put it for sixth row of new matrix of W
> > W=1 2 3 4 5 6 7 8 9
> > 2 3 4 6 7 8 1 4 5
> > ...
> >
> > how can make a loop whit for end
> > how shod define w1 to w6
> >
> > for wi=1:6 or ........
> >
> > end
> > plz help me
>
> hi
> you can do this using eval, but it's not a good idea.
> you might want to reconsider using w1 w2 w3 etc as variable names. do you really need to?
> see http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
>
> ross

dose anybody has better solution
i write this code but it dosent work
whats wrong whit this code /?
s=[];
for i=1:6
    x=reshape(w(i),9,1)
    s=[s x]
end

Subject: problem whit loop

From: Sean de

Date: 19 Nov, 2010 15:49:03

Message: 4 of 5

> dose anybody has better solution
> i write this code but it dosent work
> whats wrong whit this code /?
> s=[];
> for i=1:6
> x=reshape(w(i),9,1)
> s=[s x]
> end

size(w(i))
1x1 scalar. How can you reshape a 1x1 scalar into a 9x1 vector?

Subject: problem whit loop

From: b3hrad

Date: 22 Nov, 2010 06:54:04

Message: 5 of 5

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ic669f$lt4$1@fred.mathworks.com>...
> > dose anybody has better solution
> > i write this code but it dosent work
> > whats wrong whit this code /?
> > s=[];
> > for i=1:6
> > x=reshape(w(i),9,1)
> > s=[s x]
> > end
>
> size(w(i))
> 1x1 scalar. How can you reshape a 1x1 scalar into a 9x1 vector?

i define w(i) matrix as below :
ex:
 w1=[1 2 3; 4 5 6; 7 8 9]
w2= [2 3 4 ; 6 7 8; 1 4 5]
.
.
.
w6=[1 4 5; 1 4 8 ; 2 3 4]

how can read this matrix in a loop
plaz help me

Tags for this Thread

No tags are associated with this thread.

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.

Contact us