Concatenate a 10x4x40 Double Matrix to 40x4
1 view (last 30 days)
Show older comments
Hello,
I have a matrix A() that is 10x4x40. I would only like the first row of the matrix A(1,:,:) but want to vertically concatenate the data so it transforms into B() that is 40x4. How would I do this?
Right now I have tried doing
vertcat(A(:,:))
which returns a concatenated matrix of 1x160. Do I need to use a loop to do this? Please help!
Thank you
0 Comments
Accepted Answer
Azzi Abdelmalek
on 12 Apr 2016
A=rand(10,4,40)
B=permute(A(1,:,:),[2 1 3])
out=B(:,:)'
1 Comment
Roger Stafford
on 13 Apr 2016
Edited: Roger Stafford
on 13 Apr 2016
@Azzi: Don't you mean
B=squeeze(permute(A(1,:,:),[1,3,2]));
More Answers (1)
Fangjun Jiang
on 12 Apr 2016
reshape(A(1,:,:),40,[])
1 Comment
Roger Stafford
on 13 Apr 2016
@Fangjun: When Matthew states that a 40 x 4 array is to be produced, I believe it implicit in this statement is the assumption that what were 40-element sequences along the 3rd dimension for a given row and column index are to be preserved in the columns of the resulting 40 x 4 array. However 'reshape' will not accomplish this. To take a simpler case suppose
A = [1 2 3 4 5 6;
7 8 9 10 11 12];
We would like a 6 x 2 array B to be:
B = [1 7;
2 8;
3 9;
4 10;
5 11;
6 12]
where the former rows become the columns. However B = reshape(A,6,2) will give:
B = [1 4;
7 10;
2 5;
8 11;
3 6;
9 12]
In other words 'reshape' would break up the sequences 1,2,3,4,5,6 and 7,8,9,10,11,12. I don't think Matthew would like that as applied to the 40-element columns of the result.
However, this would work:
B = squeeze(A(1,:,:)).';
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!