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!