Concatenating ND matrices using both vertcat and horzcat

3 visualizzazioni (ultimi 30 giorni)
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?

Risposte (1)

Walter Roberson
Walter Roberson il 1 Lug 2016
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 Commenti
Varshini Guddanti
Varshini Guddanti il 5 Lug 2016
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 il 5 Lug 2016
Modificato: Stephen23 il 6 Lug 2016
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?

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by