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!