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

12 次查看(过去 30 天)
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