Plot datetime data from a cell array?

I have data set shown in fig. But I do not how to access to the data.
I try to use: plot(index{2:end, 1}, cell2mat(index(2:end, 2)), 'b'), but it does not work.

 採用された回答

Stephen23
Stephen23 2021 年 3 月 25 日
編集済み: Stephen23 2021 年 3 月 25 日

0 投票

A cell array containing lots of scalar arrays indicates that your data is arranged sub-optimally. You would be much better off using a table, or perhaps two separate homogenous vectors (i.e. a datetime array and a numeric array).
Converting to two homogenous arrays is probably the easiest way to plot the existing (badly designed) data:
dt = [index{2:end,1}];
ix = [index{2:end,2}];
plot(dt,ix)

4 件のコメント

Yufei Cao
Yufei Cao 2021 年 3 月 25 日
Hi, Stephen, Thanks for your reply and links. It helps me a lot.
Yufei Cao
Yufei Cao 2021 年 3 月 25 日
Hi, Stephen,
The orginal data is an .xlsx file. I loaded the data into matlab by using
index = readcell('index.xlsx', 'Sheet', 1);
which gives the table shown in the figure.
You mentioned the data is not well arranged. So I think you mean that I should convert index into a table?
Stephen23
Stephen23 2021 年 3 月 25 日
編集済み: Stephen23 2021 年 3 月 25 日
@Yufei Cao: try using readtable, and then access the relevant "variables" by name:
T = readtable(..);
plot(T.date,T.index)
Yufei Cao
Yufei Cao 2021 年 3 月 25 日
Hi, Stephen,
Thank you so much for the comment! The information is very useful!

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

その他の回答 (0 件)

カテゴリ

質問済み:

2021 年 3 月 25 日

コメント済み:

2021 年 3 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by