I have a 3D matrix A
, the size of which is 40*40*20
double. The values in 3D matrix is either "0"
or "1"
. The number of "1"
in matrix A is 50. I know how to find the corresponding coordinates of the 3D matrix. The code looks like this:
[x y z] = ind2sub(size(A),find(A));
coords = [x y z];
My question is how to just find the coordinates [xi yi zi] (i=1,2,...,50)
of the nonzero elements in 3D matrix A
, and then assign values a1, a2, a3, ..., a50
to the corresponding coordinates [xi yi zi] (i=1,2,...,50)
, also assign "NaN"
values to the other coordinates with zero values?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…