Find values in a 3D array based on values in a seperate 3D array

1 vue (au cours des 30 derniers jours)
KS
KS le 8 Août 2019
Commenté : KS le 8 Août 2019
I have two seperate 3D arrays that have equivalent sizes. One array (M_data) is binary. If the value of an element =1, I'd like to save the value of the corresponding position from the second array (B_data) in a matrix. So far, it looks like my code is giving me the i,j,k positions of M_data that equal 1, but it isn't referencing the B_data and it's not saving any of the data to a matrix. It's been a while since I've worked in Matlab and frankly I was never much of an expert, so any help would be much appreciated.
for i=1:size(M_data,1)
for j=1:size(M_data,2)
for k=1:size(M_data,3)
if M_data(i,j,k)==1
output= i,j,k, B_data(i,j,k);
end
end
end
end

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 8 Août 2019
lo = M_data == 1;
[ii,jj,k] = ind2sub(size(M_data),find(lo));
output = [ii,jj,k,B_data(lo)];

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by