Fgetl in a while loop.

In the code in the attached picture, does the first fgetl read the first line (Apple) and str2num(fgetl(file) read the second line (65.1)?

4 comentarios

Stephen23
Stephen23 el 3 de Abr. de 2017
Editada: Stephen23 el 3 de Abr. de 2017
You could very easily try it yourself: create that file, and write out that code. Then you would know what it does, you would gain experience with MATLAB, and you would have some working code. The more you try yourself, the more you read the documentation, the more you will learn.
As an aside: do not use str2num, the function str2double is more robust.
Jan
Jan el 3 de Abr. de 2017
fscanf is even smarter than str2double(fgetl).
Lucas  Buckels
Lucas Buckels el 4 de Abr. de 2017
I was provided the code to study from and yes I did test it, but I was still confused as to why it works. I am trying to see if that is why this code works so I know for the future.
Lucas  Buckels
Lucas Buckels el 4 de Abr. de 2017
I am still shaky using fgetl

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 4 de Abr. de 2017

0 votos

"does the first fgetl read the first line (Apple) and str2num(fgetl(file) read the second line"
Yes.
Question for you: what name is going to be reported if the file is empty?

Categorías

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 3 de Abr. de 2017

Respondida:

el 4 de Abr. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by