Find values in a 3D array based on values in a seperate 3D array
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Andrei Bobrov
2019 年 8 月 8 日
lo = M_data == 1;
[ii,jj,k] = ind2sub(size(M_data),find(lo));
output = [ii,jj,k,B_data(lo)];
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!