Filter löschen
Filter löschen

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

12 Ansichten (letzte 30 Tage)
Mingqian Chen
Mingqian Chen am 12 Feb. 2022
Kommentiert: Mingqian Chen am 12 Feb. 2022
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 Kommentar
Mingqian Chen
Mingqian Chen am 12 Feb. 2022
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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by