Concatenate a 10x4x40 Double Matrix to 40x4
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Azzi Abdelmalek
2016-4-12
A=rand(10,4,40)
B=permute(A(1,:,:),[2 1 3])
out=B(:,:)'
1 个评论
Roger Stafford
2016-4-13
编辑:Roger Stafford
2016-4-13
@Azzi: Don't you mean
B=squeeze(permute(A(1,:,:),[1,3,2]));
更多回答(1 个)
Fangjun Jiang
2016-4-12
reshape(A(1,:,:),40,[])
1 个评论
Roger Stafford
2016-4-13
@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,:,:)).';
另请参阅
类别
在 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!