arranging a matrix
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
Thomas
2012-5-15
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)
0 个评论
Jan
2012-5-15
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!