Make all values of array Nan except for specified locations

9 ビュー (過去 30 日間)
Jordan Coombs
Jordan Coombs 2020 年 12 月 2 日
コメント済み: Jordan Coombs 2020 年 12 月 2 日
I have a 2d matrix 2600x7200 and i have the locations in this matrix that i need to extract. There are 19602 of these locations.
I need a way to either make every location other than the 19602 become Nan or a way to extract these specific locations to another array of zeros.
Any help on this topic would be much appreciated

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 12 月 2 日
%%
a=magic(5);
RowPos=[1,3,5];
ColPos=[2,4,5];
ind=sub2ind(size(a),RowPos,ColPos);
b=nan(size(a));
b(ind)=a(ind);
  1 件のコメント
Jordan Coombs
Jordan Coombs 2020 年 12 月 2 日
Thank you so much, was struggling with this for ages!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by