open a text file using fopen in read mode
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to use fopen command to open a .txt file, consisting of 4 columns and 100 rows, in read mode, and scan it using fscanf command, then plot it.
But, when I use the command data=fopen('data.txt','r'), it only reads the first value
Is it possible to use fopen to open a text file?
0 comentarios
Respuestas (2)
Rik
el 11 de Jul. de 2018
As you can tell from the documentation for fopen, the output is not actually the data, but a file ID. You need a reading function to get to the actual data, as you can see from the included examples.
0 comentarios
dpb
el 11 de Jul. de 2018
Editada: dpb
el 12 de Jul. de 2018
data=fopen('data.txt','r');
fopen doesn't return data; all it does is return a file handle for fscanf, |textscan{ and friends.
What you interpreted as a value is instead the file handle; >0 means a success; <0 failure. You need to do a
fclose all
to close all active and perhaps orphaned file handles.
For a file such as you described, there's absolutely no sense in using low-level i/o functions; use importdata or readtable or one of the other high-level functions. See data-import-and-analysis for tutorial info.
0 comentarios
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!