Export data from CSV file as a vector.

2 ビュー (過去 30 日間)
Kaique Silva
Kaique Silva 2015 年 6 月 10 日
編集済み: Konstantinos Sofos 2015 年 6 月 11 日
I am using an app to try different sources of energy, the problem is that the app exports the data in CSV format, even though it is okay to get the amplitude from the file, it isn't working to get the time. It is in HH:MM:SS.FFF, and I am not being able to export it to matlab as a variable (so I can plot time vs amplitude). I have to export the B column as a vector, any idea?
  1 件のコメント
Konstantinos Sofos
Konstantinos Sofos 2015 年 6 月 10 日
Could you load a CSV as an example since we do not have any code from your side?

サインインしてコメントする。

採用された回答

Konstantinos Sofos
Konstantinos Sofos 2015 年 6 月 10 日
As I miss your sample of data, I have created one by myself (attached Data.csv). Below you can find a script that read this type of data.
fid = fopen('Data.csv');
if fid > 0
data = textscan(fid,'%d %s %f %d','Delimiter',',');
fclose(fid);
end
refTime=cellfun(@(x) datenum(x,'mm/dd/yyyy HH:MM:SS:FFF'),data(:,2),'UniformOutput',0);
plot(refTime{:},data{:,3})
datetick('x','mm/dd/yyyy HH:MM:SS:FFF');
data will be a cell array, with its second column containing all of the date strings of the format
'01/09/2014 15:27:18:322'
To convert this to number you use the datenum
Regards
  1 件のコメント
Konstantinos Sofos
Konstantinos Sofos 2015 年 6 月 11 日
編集済み: Konstantinos Sofos 2015 年 6 月 11 日
After your sample file you can load your data as
fid = fopen('SeismometerData.csv');
if fid > 0
data = textscan(fid,'%s %s %f %f %f','Delimiter',',','HeaderLines',1);
fclose(fid);
end
Timestamp = strcat(data{:,1},'', data{:,2});
TimestampNum=cellfun(@(x) datenum(x,'yyyy:mm:ddHH:MM:SS.FFF'),Timestamp,'UniformOutput',0);
TimestampNum = [TimestampNum{:}];
amplitude = [data{:,5}]';
plot(TimestampNum,amplitude)
ylabel('Amplitude')
xlabel('Clock - Time')
title('Seismometer Data')
grid on
datetick('x','HH:MM:SS');
and the result figure will be
As a reference may you have a look into the following functions textscan, cellfun and datetick.
Regards

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by