필터 지우기
필터 지우기

How to use set(h, 'XData', x...) when x is datetime or duration?

조회 수: 12 (최근 30일)
Mingqian Chen
Mingqian Chen 2022년 2월 12일
댓글: Mingqian Chen 2022년 2월 12일
Hello Guys,
I have large size csv-table with timestamp and data, i want to plot it in a better way with function set(h, 'XData', ...). After reading this page How should I update the data of a plot in Matlab? - Stack Overflow i have wrote the following approach:
tic
t = readtable('data_Mat1_2022_02_11_23_31.csv');
ax = axes;
h = plot(nan, nan);
x = t.Time;
y = t.Data;
set(h, 'YDataSource', 'y');
set(h, 'XDataSource', 'x')
n = height(t);
for i = 1:n
set(h, 'XData', x, 'YData', y);
end
toc
But when i run my code there will be the error:
Error using matlab.graphics.chart.primitive.Line/set
Value must be a vector of numeric type.
Error in plotTime (line 13)
set(h, 'XData', x, 'YData', y);
So i want to konw how to correct my code or there is another efficient way to update plot of a table, thanks for all your helps!
  댓글 수: 1
Mingqian Chen
Mingqian Chen 2022년 2월 12일
I do a little change to my code and it works
tic
t = readtable('data_Mat1_2022_02_11_23_31.csv');
ax = uiaxes;
Error using uiaxes (line 47)
This functionality is not available on remote platforms.
x = t.Time;
y = t.Data;
toc
tic
%plot(t.Time, t.Data)
h = plot(ax, x(1), y(1));
set(h, 'YDataSource', 'y');
set(h, 'XDataSource', 'x')
n = height(t);
set(h, 'XData', x, 'YData', y);
toc
Output
Elapsed time is 0.208487 seconds.
Elapsed time is 0.006211 seconds.
Maybe the bottleneck is the time of reading table

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by