how to return indices?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I have a 3 dimensional data matrix (72*45*2109), and I need to extract all data less than 15. the final output should be a 3d matrix
I used the following lines, but the result is a vector. The point is to return the indices to have 3d matrix.
Any help would be greatly appreciated.
[r,c,v] = ind2sub(size(data),find(data >= 15));
l = data(sub2ind(size(data),r,c,v));
2 件のコメント
DGM
2022 年 6 月 12 日
編集済み: DGM
2022 年 6 月 12 日
You get a vector, because those are the indices of elements that you wanted -- only the indices you wanted.
Arrays need to be rectangular, without holes.
With that restriction, you'll have to decide what you want to fill all the area where there are elements you didn't want. It could be zero, NaN, etc. It's up to you and what the subequent code can accept without causing errors, since neither zero nor NaN are valid indices.
採用された回答
Dyuman Joshi
2022 年 6 月 12 日
Based on your comment -
%random data
y=randi(30,2,3,4)
z=NaN(2,3,4);
z(y<15)=y(y<15)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!