If isnan(x) make columns also NaN
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I have a horizontal array or data 1:1505 made of Nans and 1s (inA4)
I also have a matrix of data 96:1505 (Approx4)
Where ever a NaN appears in 'inA1' I want the entire column of Approx 1 to become NaNs.
This is what I have come up with so far, but It's not working. I'm sure the solution is simple but I can not work it out thus far
      for i = 1:96;
          j = 1:1505;
         if inA4(j) == 1;
             Approx4(i,j) = Approx4(i,j);
         else isnan(Approx4(i,j));
         end;
      end;
0 comentarios
Respuestas (2)
  Stephen23
      
      
 el 10 de Feb. de 2016
        
      Editada: Stephen23
      
      
 el 10 de Feb. de 2016
  
      This is trivial using basic MATLAB indexing:
>> A =  [1,2,3;4,5,6;7,8,9]
A =
   1   2   3
   4   5   6
   7   8   9
>> B = [1,NaN,1]
B =
     1   NaN     1
>> A(:,isnan(B)) = NaN
A =
     1   NaN     3
     4   NaN     6
     7   NaN     9
You should learn to how use MATLAB instead of fighting it with inefficient loops:
0 comentarios
  Wolfgang
      
 el 10 de Feb. de 2016
         idxNaNs = isnan(inA4);    % find NaNs in inA4
 Approx4(:,idxNaNs) = NaN; % set columns to NaN
0 comentarios
Ver también
Categorías
				Más información sobre Matrix Indexing en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


