help using fgetl???
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Geoff
el 27 de Mzo. de 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.
4 comentarios
Joey
el 27 de Mzo. de 2012
Joey
el 27 de Mzo. de 2012
Geoff
el 27 de Mzo. de 2012
You really need to read the documentation for these functions. Read, then experiment, and you will become familiar. Type in 'help regexp' for quick help, or 'doc regexp' for more detailed help.
Joey
el 27 de Mzo. de 2012
Categorías
Más información sobre Text Data Preparation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!