Reading data from a text file
30 ビュー (過去 30 日間)
古いコメントを表示
Hallo
I usually used load function to read text files. However, this time my text file has the first column as p1 p2 p3 and so on. How can I not read this column and load only the next available columns. I used fopen, fscanf and fclose but it gives an empty array as output.
Thanks in advance.
0 件のコメント
採用された回答
Narges M
2013 年 7 月 25 日
編集済み: Narges M
2013 年 7 月 25 日
use this example:
cfg = fopen('myfile.txt');
line = fgetl(cfg); %this line reads the first line, you can discard it right away
while( ~feof(cfg) )
line = fgetl(cfg);
% read your data here, using textscan for example
end
or use this:
f = fopen('myfile.txt');
E = textscan(f,'%s %f %f %f','delimiter', ' ', 'collectoutput',false,'BufSize',10000);
end
11 件のコメント
その他の回答 (1 件)
kjetil87
2013 年 7 月 25 日
編集済み: kjetil87
2013 年 7 月 25 日
perhaps you are using fscanf(fid,'%d') ?
Try reading it as characters:
fid=fopen('text.txt');
DATA=fscanf(fid,'%c');
fclose(fid);
4 件のコメント
Narges M
2013 年 7 月 25 日
E = textscan(f,'%s %f %f %f','delimiter', ' ', 'collectoutput',false,'BufSize',10000);
参考
カテゴリ
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!