load columns from file with headlines and dates
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
date, Value(1) , Value(2) , Value(3) , Value(4) ........,Value(200)
date, ?, ?, ?, ?
2010/10/01 00:00:00, 0 , 0 , 0 , 0 ,....
2010/10/01 01:00:00, 12, 5.4, 0 , 0 ,....
2010/10/01 02:00:00, 7.6, 3.99, 1.18, 0 ,...
2010/10/01 03:00:00, 4.06, 0.0008, 4.05, 6.84,...
2010/10/01 04:00:00, 1.44, 0.0020, 4.096, 8.14,...
Hi!
I have a file like the one above (with headers and dates on the first column). With few columns I'm opening it with importfile('myfile.csv');
However I want to load only from, for example, column 100 to column 101. Any suggestions? I was trying with: dlmread('myfile',',','headlines',2) but doesnt work
Thanks
0 Kommentare
Antworten (2)
Chandrasekhar
am 23 Apr. 2013
it can be read by using csvread command of matlab
2 Kommentare
Matt Kindig
am 23 Apr. 2013
Bearbeitet: Matt Kindig
am 23 Apr. 2013
I think this should work using textread():
Format = ['%*s %*s ', repmat('%*f', [1 98]), '%f %f', '%*[\n]'];
data = textread('/path/to/your/file.csv', Format, 'delimiter', ',', 'headerLines', 2);
Cedric
am 23 Apr. 2013
Bearbeitet: Cedric
am 23 Apr. 2013
Assuming that the date/time column has always the same format, the first value starts at char 22 and you can do something like:
cols = [100, 101] ;
buffer = zeros(1e6, length(cols)) ; % Prealloc for 1e6 entries.
fid = fopen('myFile.csv', 'r') ;
lCnt = 0 ;
while (~feof(fid))
line = fgetl(fid) ;
if line(1) == 'd', continue ; end % Skip lines starting with 'd'.
lCnt = lCnt + 1 ;
values = textscan(line(22:end), '%f,', Inf) ;
buffer(lCnt,:) = values{1}(cols) ;
end
fclose(fid) ;
buffer = buffer(1:lCnt,:) ; % Truncate to number of records.
Note that you might want to realloc buffer when lCnt hits 1e6 (or whichever value you are using for the prealloc). Also, a TEXTREAD guru could probably do this in one shot using this function.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Variables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!