Effacer les filtres
Effacer les filtres

arranging a matrix

2 vues (au cours des 30 derniers jours)
madhuri sachane
madhuri sachane le 15 Mai 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.

Réponses (2)

Thomas
Thomas le 15 Mai 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 le 15 Mai 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);

Community Treasure Hunt

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

Start Hunting!

Translated by