フィルターのクリア

Why does textscan only read the first row of my text file?

20 ビュー (過去 30 日間)
Samuele Bolotta
Samuele Bolotta 2020 年 5 月 1 日
コメント済み: Samuele Bolotta 2020 年 5 月 11 日
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.

採用された回答

Vimal Rathod
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!
  1 件のコメント
Samuele Bolotta
Samuele Bolotta 2020 年 5 月 11 日
Thanks! What if I now want to access the other columns, from 3 to 7? Why doesn't it become:
b = textscan(fileids{file},'%*[^\n] %n %n', -1, 'delimiter', '\t', 'EndOfLine','\r\n');
I'm trying it out but I get this error:
Index exceeds the number of array elements (5).
Error in SocialTest (line 21)
count = b{6};

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by