Loading delimited text file
古いコメントを表示
I'm having trouble loading the following text file. That is delimited as such: --------------
116,1.7874926329,-426.0292053223,45.1162757874; 13P 226
116,2.7424895763,-426.0281066895,45.0740852356; 15P 227
116,3.7051227093,-426.0320434570,45.0093040466; 17P 228
-------------- (ignore spaces between lines, that's just for the forum)
I want all the rows but only columns 1-3.
I tried dlmread('data.txt', ',', 0, 1) but that gives me a bunch of 0 rows and doesn't capture all the rows.
Any suggestions?
回答 (1 件)
Fangjun Jiang
2011 年 8 月 30 日
use importdata(). Ignore the empty lines between data lines. Also ignore your dash lines.
>> a=importdata('test.txt')
a =
116 1.7875 -426.03 45.116 13 226
116 2.7425 -426.03 45.074 15 227
116 3.7051 -426.03 45.009 17 228
>> b=a(:,1:3)
b =
116 1.7875 -426.03
116 2.7425 -426.03
116 3.7051 -426.03
4 件のコメント
lex
2011 年 8 月 31 日
Fangjun Jiang
2011 年 8 月 31 日
All right, importdata() differs at different MATLAB version.
fid=fopen('test.txt','rt');
a=textscan(fid,'%f,%f,%f%*[^\n]','collectoutput',1);
fclose(fid);
a =
[5x3 double]
>> a{1}
ans =
116.0000 1.7875 -426.0292
116.0000 2.7425 -426.0281
116.0000 3.7051 -426.0320
116.0000 4.6661 -426.0295
116.0000 5.6226 -426.0305
lex
2011 年 9 月 1 日
Fangjun Jiang
2011 年 9 月 1 日
Then don't use it. a=textscan(fid,'%f,%f,%f%*[^\n]') works too. The result is in a{1},a{2},a{3}.
カテゴリ
ヘルプ センター および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!