Selecting numbers out of a text file?

1 visualización (últimos 30 días)
Lauren Harkness
Lauren Harkness el 12 de Oct. de 2017
Editada: Jonathan Chin el 12 de Oct. de 2017
So I have a text file with a list of scores, I have used strtok to get the text file to just show up as numbers in a list separated by commas, how do I go from this list to just an array of the numbers. for example
'0,1,2,3' '9,8.2,5,6' '4,8,4,5' '.2,4,3,2' to [0 1 2 3 9 8.2 5 6 4 8 4 5 .2 4 3 2]

Respuestas (1)

Jonathan Chin
Jonathan Chin el 12 de Oct. de 2017
Editada: Jonathan Chin el 12 de Oct. de 2017
Take a look at str2num
txt='0,1,2,3,9,8.2,5,6,4,8,4,5,.2,4,3,2';
numArray=str2num(txt)
if txt is a cell array you can use cellfun and str2num
txt={'0,1,2,3' '9,8.2,5,6' '4,8,4,5' '.2,4,3,2'}
tmp=cellfun(@str2num,txt,'UniformOutput',false)
numArray = [tmp{:}]

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by