Selecting numbers out of a text file?
1 view (last 30 days)
Show older comments
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]
0 Comments
Answers (1)
Jonathan Chin
on 12 Oct 2017
Edited: Jonathan Chin
on 12 Oct 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{:}]
0 Comments
See Also
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!