필터 지우기
필터 지우기

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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by