convert excel date and time to matlab

7 ビュー (過去 30 日間)
Galgool
Galgool 2019 年 6 月 27 日
コメント済み: Galgool 2019 年 6 月 28 日
Hi,
I have read many posts about this but just cant get it to work.
I have R2014a and I'm currently using xlsread to read from an excel date and time file, which doesnt give me what I want which is to use as the time axix in plot.
Is there a way?
excel:
Capture.JPG
matlab:
Capture2.JPG
  2 件のコメント
Murugan C
Murugan C 2019 年 6 月 28 日
Could pleae attach your excel sheet?
Guillaume
Guillaume 2019 年 6 月 28 日
編集済み: Guillaume 2019 年 6 月 28 日
The simple reason that you're not getting datetime in matlab is because your date and time is not stored as date and time in Excel (well the time may be, but certainly not the date).
It looks like your date is stored as plain numbers. These can be trivially converted to date and added to the time. We would need to know which format (year-momth-day or year-day-month?) is used to give you the proper code.
An example excel file wouldn't hurt.
Finally, are you on an old version of matlab which prevent you from using the more modern readtable instead of xlsread?

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 6 月 28 日
data = [ 9264 20180104 0.8021
9265 20180104 0.8125
9266 20180104 0.8229
9267 20180104 0.8333
9268 20180104 0.8438
9269 20180104 0.8542
9270 20180104 0.8646
9265 20180104 0.8021
9271 20180104 0.8125
9272 20180104 0.8229
9273 20180104 0.8333 ];
dateout = datetime(data(:,2),'ConvertFrom','yyyymmdd') + data(:,3);
or for old MATLAB
dateoutnum = datenum(sprintfc('%d',data(:,2)),'yyyymmdd') + data(:,3);
dateoutstr = datestr(dateoutnum);
  1 件のコメント
Galgool
Galgool 2019 年 6 月 28 日
Great, it works
And how can I use it in plot for the x axis?
Its giving me an arror:
plot(dateoutstr,clos,'b')
Error using plot
Invalid first data argument

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

その他の回答 (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