adding 2D array to 3D array

1 Ansicht (letzte 30 Tage)
sermet OGUTCU
sermet OGUTCU am 27 Okt. 2021
Bearbeitet: DGM am 27 Okt. 2021
I have a 3D data matrix (data_3D = 285 x 1 x 32). I need to add data_3D(:,:,1) to the beginning of data_3D. For example:
data_3D=
val(:,:,1) =
0.4071
0.3264
0.2420
.
.
val(:,:,2) =
1.6763
1.7567
1.8351
.
.
val(:,:,3) =
-0.4985
-0.4467
-0.3952
.
.
When data_3D(:,:,1) is added to the beginning of data_3D, data_3D should be:
data_3D=
val(:,:,1) =
0.4071
0.3264
0.2420
.
.
val(:,:,2) =
0.4071
0.3264
0.2420
.
.
val(:,:,3) =
1.6763
1.7567
1.8351
.
.
val(:,:,4) =
-0.4985
-0.4467
-0.3952
.
.

Akzeptierte Antwort

DGM
DGM am 27 Okt. 2021
Bearbeitet: DGM am 27 Okt. 2021
An example:
A = randi(100,3,1,4)
A =
A(:,:,1) = 77 10 37 A(:,:,2) = 66 92 64 A(:,:,3) = 50 26 55 A(:,:,4) = 34 33 2
B = A(:,:,[1 1:end])
B =
B(:,:,1) = 77 10 37 B(:,:,2) = 77 10 37 B(:,:,3) = 66 92 64 B(:,:,4) = 50 26 55 B(:,:,5) = 34 33 2
Alternatively, you can do the concatenation just using cat()
C = cat(3,A(:,:,1),A)
C =
C(:,:,1) = 77 10 37 C(:,:,2) = 77 10 37 C(:,:,3) = 66 92 64 C(:,:,4) = 50 26 55 C(:,:,5) = 34 33 2

Weitere Antworten (0)

Kategorien

Mehr zu Mechanical Engineering finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by