フィルターのクリア

load columns from file with headlines and dates

4 ビュー (過去 30 日間)
Ana
Ana 2013 年 4 月 23 日
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

回答 (2 件)

Chandrasekhar
Chandrasekhar 2013 年 4 月 23 日
it can be read by using csvread command of matlab
  2 件のコメント
Ana
Ana 2013 年 4 月 23 日
It's not working. the file has headlines and the first column of the files are dates...
Matt Kindig
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
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.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by