Why does textscan only read the first row of my text file?
20 次查看(过去 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!