How to access certain matrix elements and turn into NaN?
    4 views (last 30 days)
  
       Show older comments
    
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.
0 Comments
Accepted Answer
  cbrysch
      
 on 18 Aug 2016
        z(find(interior))=NaN;
should work. It is better to vectorize your data than using a loop.
More Answers (0)
See Also
Categories
				Find more on Creating and Concatenating Matrices in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
