open a text file using fopen in read mode
이전 댓글 표시
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?
답변 (2개)
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.
카테고리
도움말 센터 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!