Hello, i have a table with many rows and 3 columns. In the first column some values are NaN. How can i put NaN values in the other columns in the same rows?
    7 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Christina Geo
 am 7 Jul. 2021
  
    
    
    
    
    Beantwortet: dpb
      
      
 am 7 Jul. 2021
            for example
A = 
    A1     A2    A3
    ___    __    __
    NaN    4     7 
    NaN    5     8 
      3       6     9
and I would like to have 
A = 
    A1     A2    A3
    ___    __    __
    NaN    NaN    NaN 
    NaN    NaN    NaN
      3       6         9
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (2)
  dpb
      
      
 am 7 Jul. 2021
        Use logical indexing; no loops needed --
>> A{isnan(A.A1),:}=nan
A =
  3×3 table
    A1     A2     A3 
    ___    ___    ___
    NaN    NaN    NaN
    NaN    NaN    NaN
      3      6      9
>> 
NB: the "curlies" to return an array from the indexing operation on the LHS, smooth parens here would return a table instead.
See the documentation for the table class for a detailed exposition on addressing modes and syntax for tables--there's a "veritable plethora" of ways to do so.
0 Kommentare
  Soniya Jain
      
 am 7 Jul. 2021
        
      Bearbeitet: Soniya Jain
      
 am 7 Jul. 2021
  
      Hey, you can use isnan() function to find the location where values are NaN in the 1st column,
A = [NaN,4,7; NaN,5,8; 3,6,9];
nanV = isnan(A(:,1));
for i=1:height(A)
    if nanV(i,1) == 1
        A(i,:) = NaN;
    end
end
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Tables finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



