フィルターのクリア

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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by