Concatenating ND matrices using both vertcat and horzcat

2 次查看(过去 30 天)
Hi All, I have a 4x39x7 matrix I wanted a resultant matrix which looks like this:
(1,1,1)(1,2,1)(1,3,1)(1,4,1)...........................(1,39,1) - horzcat of all each of these cells(ex : A1)
(2,1,1)(2,2,1)(2,3,1)(2,4,1)...........................(2,39,1) - horzcat of all each of these cells(ex : A2)
(3,1,1)..........................................................(3,39,1) - horzcat of all each of these cells(ex : A3)
(4,1,1)..........................................................(4,39,1) - horzcat of all each of these cells(ex : A4)
(1,1,2)..........................................................(1,39,2) - horzcat of all each of these cells(ex : A5)
(2,1,2)..........................................................(2,39,2) - horzcat of all each of these cells(ex : A6)
(3,1,2)..........................................................(3,39,2) - horzcat of all each of these cells(ex : A7)
(4,1,2)..........................................................(4,39,2) - horzcat of all each of these cells(ex : A8)
.
.
.
.(4,1,7).........................................................(4,39,7) - horzcat of all each of these cells(ex : A28)
temp = vertcat(A1,A2,.............A28);
So, finally I need to do horizontal concatenation of each of these cells and then vertical concatenation of all the formed cells.
Can anyone help me doing this?

回答(1 个)

Walter Roberson
Walter Roberson 2016-7-1
It looks to me as if that would just be the following
temp = reshape(YourMatrix, [], size(YourMatrix,2));
with no individual variables or loops required.
  2 个评论
Varshini Guddanti
Thanks for the reply! But my intention of asking the question was different. Each cell in turn has two matrices one below the other here. So, I want to concatenate the contents of the first matrix of each cell in the manner I depicted above.
For example: Matrix{1,1,1}
ans(:,:,1) =
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
ans(:,:,2) =
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7
Do you have any suggestion?
Thanks
Walter Roberson
Walter Roberson 2016-7-5
编辑:Stephen23 2016-7-6
Could you confirm then that you have a 4x39x7 cell array? If so then what is known about the contents of the cells? Your example with Matrix implies that they might be a single 3D numeric array with 2 pages, but is that always the case? Are the arrays stored in the cell always going to be the same size as each other? Are they always going to be the same data type? Is it certain that there will only be one numeric array in each cell?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by