help using fgetl???
Show older comments
In the problem that i am currently on i have to use the data file mm.dat that looks like this
{33,2,11}
{45,9,3}
and use fgetl in a loop to read the data in. Then i am to create a matrix that stores just the numbers, and write the matrix to a new file. Assume that each line in the original file contains the same number of numbers.
i have this so far, but i cant figure out how to read only the numbers from the data and not the commas or the {}.
cat = fopen('mm.dat');
if cat == -1
disp('file did not open')
else
while feof(cat) == 0
evrline = fgetl(cat)
num = strtok(evrline)
save probtwenonewfile num
end
closeresult = fclose(cat);
end
Accepted Answer
More Answers (1)
Geoff
on 27 Mar 2012
Is this an assignment for a course you are doing?
Do you have to use strtok? Or can you use something like regexp or textscan?
Using strtok is okay, if you use it properly:
doc strtok
You will need to extract one token at a time until there are no more. Hint: set delimiters to any characters you don't want.
Are the numbers non-negative integers?
I would probably use regexp.
Categories
Find more on Text Data Preparation 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!