How to keep only numbers in a cell (.xlsx file)?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ivan Mich
el 7 de Feb. de 2021
I have an .xlsx file. In one column there are numbers and text in each cell (e.g. 0.562550 (AHV)).
How could I keep ONLY the number of each cell (e.g. ONLY the 0.562550) ??
I am uploading the file in order to understand.
Thank you in advance
0 comentarios
Respuesta aceptada
Walter Roberson
el 7 de Feb. de 2021
c = readcell('test.xlsx');
data = cellfun(@(C) str2double(regexprep(C, '\(.*', '')), c)
0 comentarios
Más respuestas (1)
Ive J
el 7 de Feb. de 2021
Editada: Ive J
el 7 de Feb. de 2021
x = readcell('test.xlsx')
nums = cellfun(@(x)sscanf(x, '%f', 1), x)
1.4420
0.3320
0.3560
0.8530
250.8690
8.8190
2 comentarios
Walter Roberson
el 7 de Feb. de 2021
Good point. Though I might suggest adding a size to the sscanf() to prevent it from trying to look for more values, and as a guard against the possibility of having a second value that looked like a number in the cell.
Ver también
Categorías
Más información sobre Migrate GUIDE Apps 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!