pasting row elements as matrix
3 次查看(过去 30 天)
显示 更早的评论
Hi All, I new with matlab and right now am into a difficulty such that,I have a matrix like below b11 =
1 2
3 4
5 6
7 8
9 10
11 12
13 14
Now I am trying to create a new matrix (C) from this b11 matrix such that all elements in first row are copied in C with N replications and then same should be done for the next row till we reach last rowof b11 and the order of the C matrix will be (N) x (cols(b11)*rows(b11))!
I am trying this two for loops such that
for p=1:2:11
for i=1:6
b111(:,p:p+1)=repmat(b11(i,:),174,1);
end
end
But instead of looping and replicating all elements of each row, I only get the last two rows replicated 6 times which is required to be last two columns of C matrixotherwise.
Any help will be great since I am just beginning here.
Thanks and Regards
Nader
2 个评论
Sean de Wolski
2011-5-11
Can you provide the expected result for this example (or subset of this example)?
i.e.
What do you want it b11 = [1 2; 3 4]
采纳的回答
Sean de Wolski
2011-5-12
b = [ 1 2
3 4
5 6
7 8
9 10
11 12
13 14];
N = 7;
c = repmat(reshape(b.',numel(b),1).',N,1)
If this is not what you want, please give the result as Andrei and I have suggested.
更多回答(3 个)
Laura Proctor
2011-5-11
I think that you would like something like this:
N = 10;
C = repmat(b11,[1,1,N]);
C = permute(C,[3,2,1]); % to bring it to the size N * cols * rows
But, seeing the expected result would be helpful... I'm not sure if you want a 3D matrix or a 2D matrix - I created a 3D matrix because of what you term the "order of the C matrix".
Originally, upon reading your question, I thought something like this code would be the solution:
C = repmat(b1,1,N);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!