How to identify strings that can be converted to float numbers in a cell array?
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Leon
 el 11 de Mzo. de 2025
  
    
    
    
    
    Comentada: Walter Roberson
      
      
 el 11 de Mzo. de 2025
            I can convert a string to double using str2double, but my goal is to identify such cells. Attached is an example file. 
A = readcell('test6.xlsx');
As you can see, some cells on the 2nd column meet this criteria. 
Many thanks. 
1 comentario
Respuesta aceptada
  Les Beckham
      
 el 11 de Mzo. de 2025
        I would suggest using readtable instead of readcell
A = readcell('test6.xlsx')
You can define the variable types so Matlab knows which columns (variables) are supposed to be numeric.
opts = detectImportOptions('test6.xlsx');
opts.VariableTypes =  { 'char', 'double', 'double', 'double', 'double', 'double' };
T = readtable('test6.xlsx', opts)
And, if you really want a cell array instead of a table:
C = table2cell(T)
9 comentarios
  Les Beckham
      
 el 11 de Mzo. de 2025
				Note that str2double will give you the same mask. It returns NaN for anything that it can't convert.
A = readcell('test6.xlsx');
mask = ~isnan(str2double(A))
  Walter Roberson
      
      
 el 11 de Mzo. de 2025
				Yes. You specifically wanted a method that did not use str2double() (for reasons that are not clear to us).
Ver también
Categorías
				Más información sobre Spreadsheets en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!