Loading delimited text file
Ältere Kommentare anzeigen
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?
Antworten (1)
Fangjun Jiang
am 30 Aug. 2011
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 Kommentare
lex
am 31 Aug. 2011
Fangjun Jiang
am 31 Aug. 2011
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
am 1 Sep. 2011
Fangjun Jiang
am 1 Sep. 2011
Then don't use it. a=textscan(fid,'%f,%f,%f%*[^\n]') works too. The result is in a{1},a{2},a{3}.
Kategorien
Mehr zu Large Files and Big Data finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!