Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: double for loop
Replies: 5   Last Post: Sep 9, 2013 10:29 AM

 Messages: [ Previous | Next ]
 Steven Lord Posts: 18,038 Registered: 12/7/04
Re: double for loop
Posted: Sep 9, 2013 10:29 AM

"cwc " <Darrylcwc@live.com.sg> wrote in message
news:l0kbli\$em6\$1@newscl01ah.mathworks.com...
> I don't understand the process as to how
> [1,2;3,4;5,6]
>
> gets to
> [ 1 1 2 2
> 1 1 2 2
> 3 3 4 4
> 3 3 4 4 5 5 6 6
> 5 5 6 6 ]
>
> if ii and jj represents the length of the original matrix then why would
> it double?

Please post the EXACT code you run that generates this new larger matrix.
The original code you posted:

> [x,y] = size(z)
>
> for ii = 1:x;
> for jj = 1:y;
>
> newz = z(ii,jj)
>
> end

does NOT do this (assuming we add the extra end to close the first FOR
loop.)

If on the other hand you WANT to obtain that larger matrix, use the KRON
function.

--
Steve Lord
slord@mathworks.com
http://www.mathworks.com

Date Subject Author
9/9/13 cwc
9/9/13 Nasser Abbasi
9/9/13 cwc
9/9/13 dpb
9/9/13 cwc
9/9/13 Steven Lord