Any suggestion to replace the diagonal values of matrices in a 3D array?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
julian gaviria
am 6 Nov. 2023
Kommentiert: Dyuman Joshi
am 6 Nov. 2023
Any suggestion to replace the diagonal values of matrices in a 3D array?
in case1 to "0"
in case1 to "NaN"
e.g. for NaN
M_3D=randi(100, 4,4,3); %fake input
N=size(M_3D,1);
mask=1:N+1:end)=nan;
M_3D=M_3D.*mask;
4 Kommentare
Steven Lord
am 6 Nov. 2023
One possibility is points at subscripts n*ones(1, ndimsOfArray) for n = 1:min(size(theArray)). Once you reach any "edge" of the array you stop.
So for an array of size (4, 3, 5) those would be the elements at subscripts (1, 1, 1), (2, 2, 2), and (3, 3, 3). That matches conceptually the behavior of the diag function on non-square matrices.
A = reshape(1:12, 3, 4)
diag(A) % (1, 1), (2, 2), and (3, 3) since min(size(A)) is 3.
Akzeptierte Antwort
Dyuman Joshi
am 6 Nov. 2023
Replacing diagonal values of each 2D matrix of a 3D matrix with NaN
M = randi(100, 4,4,3); %fake input
N = eye(size(M,[1 2]));
M(M&N)=NaN
4 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots 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!