2D matrix to 3D

1 Ansicht (letzte 30 Tage)
Chaodong Li
Chaodong Li am 5 Jun. 2019
Kommentiert: madhan ravi am 5 Jun. 2019
Can anyone help me with making a 2D matrix into a 3D matrix?I have aI have a (616*780) 2d matrix and I need to make a 3D matrix of dimensions (616*780 x M) I need to take (616*780) consecutive matrices by row for layers,where M is the max value in the 2d matrix. Means I want to slice the 2D matrix.
I would appreciate it if anyone could help me! Thank you very much!

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 5 Jun. 2019
Bearbeitet: KALYAN ACHARJYA am 5 Jun. 2019
Here I used the multidimetional arrays
mat1(:,:,1)=[1,2,3,4; 5,6,7,8; 9,10,11,12];
mat1(:,:,2)=[1,2,3,4; 5,6,7,8; 9,10,11,12];
mat1(:,:,3)=[1,2,3,4; 5,6,7,8; 9,10,11,12];
disp(mat1);
Result:
(:,:,1) =
1 2 3 4
5 6 7 8
9 10 11 12
(:,:,2) =
1 2 3 4
5 6 7 8
9 10 11 12
(:,:,3) =
1 2 3 4
5 6 7 8
9 10 11 12
Check?
>> whos mat1
Name Size Bytes Class Attributes
mat1 3x4x3 288 double
>>
  2 Kommentare
Chaodong Li
Chaodong Li am 5 Jun. 2019
Thank you very much.But my two dimensional matrices have different values.I'm actually representing terrain information in a two-dimensional matrix,evey value is elevation.Can i still use that notation?and how to write the code?
madhan ravi
madhan ravi am 5 Jun. 2019
Huh?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

madhan ravi
madhan ravi am 5 Jun. 2019
repmat(a,1,1,max(a(:))) % where a is your matrix if you have decimals in your matrix then use round function for max() to make the max value as an integer

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by