pasting row elements as matrix
3 views (last 30 days)
Show older comments
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 Comments
Sean de Wolski
on 11 May 2011
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]
Accepted Answer
Sean de Wolski
on 12 May 2011
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.
More Answers (3)
Laura Proctor
on 11 May 2011
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 Comments
See Also
Categories
Find more on Creating and Concatenating 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!