Azzera filtri
Azzera filtri

Selecting numbers out of a text file?

1 visualizzazione (ultimi 30 giorni)
Lauren Harkness
Lauren Harkness il 12 Ott 2017
Modificato: Jonathan Chin il 12 Ott 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]

Risposte (1)

Jonathan Chin
Jonathan Chin il 12 Ott 2017
Modificato: Jonathan Chin il 12 Ott 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{:}]

Community Treasure Hunt

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

Start Hunting!

Translated by