arranging a matrix

1 view (last 30 days)
madhuri sachane
madhuri sachane on 15 May 2012
I have to create a matrix of dimension 240*7. I got one submatrix of 2*7 which is in a loop. there are 120 iteration for each time I got the 2*7 matrix. from these 2*7 matrices I want to create a 240*7 matrix. I don't know How to do it.how to arrange them. Now I need to combine these matrices into one large matrix; how do I do that? please help me.

Answers (2)

Thomas
Thomas on 15 May 2012
Perhaps you need something like this..
c=[];
for ii=1:120
a=rand(2,7); %generate 2x7 matrix every loop
c=[c;a]; % every loop concatenates new 'a' to current output
end
size(c)

Jan
Jan on 15 May 2012
A pre-allocation is important:
c = zeros(240, 7);
for ii = 1:2:240
a = rand(2,7);
c(ii:ii+1, :) = a;
end
An similar approach:
c = zeros(120, 2, 7);
for ii = 1:120
a = rand(2,7);
c(:, ii, :) = a;
end
c = reshape(c, 240, 7);

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!