Plot datetime data from a cell array?

조회 수: 7 (최근 30일)
Yufei Cao
Yufei Cao 2021년 3월 25일
댓글: Yufei Cao 2021년 3월 25일
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일
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
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개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by