フィルターのクリア

How to access certain matrix elements and turn into NaN?

2 ビュー (過去 30 日間)
RG
RG 2016 年 8 月 18 日
コメント済み: RG 2016 年 8 月 18 日
Hi,
I have two matrices z and interior as shown below:
z =[ 9.0000 17.6400 29.1600 43.5600 60.8400 81.0000;
6.7493 13.2287 21.8679 32.6668 45.6255 60.7440;
1.1230 2.2011 3.6386 5.4354 7.5916 10.1071;
-5.0650 -9.9274 -16.4105 -24.5145 -34.2393 -45.5848;
-8.7197 -17.0907 -28.2520 -42.2035 -58.9454 -78.4777;
-8.0134 -15.7062 -25.9633 -38.7846 -54.1703 -72.1202]
interior =[ 0 0 0 0 0 0;
0 0 0 0 0 0;
0 0 1 1 0 0;
0 0 1 1 0 0;
0 0 0 0 0 0;
0 0 0 0 0 0]
I am trying to extract the subscript indices of elements that are 1 in a matrix called interior and then turn the elements with same subscript indices (i.e [3.6386 5.4354; -16.4105 -24.5145]) into NaN in a matrix called z.
So far I have tried to extract the subscript indices as below:
[row,col] = find(interior)
combine = [row, col]
And I tried to use for loop to access the elements with same subscript indices in a matrix z, but couldn't work my way out. Could I get some help on this please? Sorry if it is a too simple question.

採用された回答

cbrysch
cbrysch 2016 年 8 月 18 日
z(find(interior))=NaN;
should work. It is better to vectorize your data than using a loop.
  1 件のコメント
RG
RG 2016 年 8 月 18 日
Excellent!! That did the trick. Thanks a lot.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by