load columns from file with headlines and dates
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Chandrasekhar
2013년 4월 23일
it can be read by using csvread command of matlab
댓글 수: 2
Matt Kindig
2013년 4월 23일
편집: Matt Kindig
2013년 4월 23일
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
2013년 4월 23일
편집: Cedric
2013년 4월 23일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!