help using fgetl???
显示 更早的评论
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
采纳的回答
更多回答(1 个)
Geoff
2012-3-27
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!