Adding matrices to a 3D matrix in a specific order
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Say I have a 3D matrix 50x50x100
Now I want to add another matrix to make it 50x50x101, however I want the new matrix to go in a particular position e.g. the 10th out of the 101 matrices.
How can I achieve this?
0 Kommentare
Antworten (1)
Stephen23
am 3 Nov. 2015
Bearbeitet: Stephen23
am 3 Nov. 2015
This is easy using MATLAB indexing. Here is an example with 2D matrices, to show how indexing can be used to insert values in particular locations of a new matrix:
>> M = [1,2,3;4,5,6] % original matrix
M =
1 2 3
4 5 6
>> N(:,[1,3:4]) = M % insert M into cols 1,3 and 4 of N
N =
1 0 2 3
4 0 5 6
>> N(:,2) = [Inf,NaN] % insert into col 2 of N
N =
1 Inf 2 3
4 NaN 5 6
And here is a 3D example as well:
>> X = reshape([1,2,3,4,5,6],1,2,3); % original array
>> Y(:,:,[1,3:4]) = X; % insert into pages 1, 3 and 4 of Y
>> Y(:,:,2) = [Inf,NaN] % insert into page 2 of Y
Y(:,:,1) =
1 2
Y(:,:,2) =
Inf NaN
Y(:,:,3) =
3 4
Y(:,:,4) =
5 6
More information on indexing:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!