Why does textscan only read the first row of my text file?
조회 수: 18 (최근 30일)
이전 댓글 표시
for file = 1:total_files
[inputfile,path] = uigetfile('*.txt');
fileids{file} = fopen(fullfile(path, inputfile));
if fileids{file} == -1
error('Failed to open file "%s"', fullfile(path, inputfile));
end
b = textscan(fileids{file},'%n %n %*n %*n %*n %*n %*n',-1, 'delimiter', '/t');
events = b{1};
event_times = b{2};
I want to read in only fhe first two columns out of 7. This works. However, I can only read in the first row.
댓글 수: 0
채택된 답변
Vimal Rathod
2020년 5월 4일
Hi,
Instead of using the below line,
b = textscan(fileids{file},'%n %n %*n %*n %*n %*n %*n',-1, 'delimiter', '/t');
use this,
b = textscan(fileids{file},'%n %n %*[^\n]', -1, 'delimiter', '\t', 'EndOfLine','\r\n');
you will be able to access the data properly.
Hope this helps!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!