Real Time Data Plot

6 Ansichten (letzte 30 Tage)
mehmet kelleci
mehmet kelleci am 2 Apr. 2020
Beantwortet: Geoff Hayes am 2 Apr. 2020
Hello,
Is there possibly a way of real time data plotting in an efficient way? Here below I have written that piece of code as an example. But, I do not believe that it is efficient. Any suggestions? Thank you very much.
MK
clc, clear all, close all, format long;
time = linspace(0,100,100);
x = rand(100,1);
%fig = plot(NaN,NaN,'r');
figure(1)
for i = 1:100
a(i) = time(i);
b(i) = x(i);
plot(a,b)
axis([0 100 0 1.2])
grid on;
% set(fig,'XData',a,'YData',b);
% set(fig,'Visible','on');
pause(0.001)
end

Antworten (1)

Geoff Hayes
Geoff Hayes am 2 Apr. 2020
mehmet - every time you call plot you create a new graphics object, so you could just re-use a single plot object on every iteration of the loop. You seem to have some of the code already there just commented out and incorrectly referencing the (suppposed) figure handle when instead it should be the handle to the plot. For example,
close all, format long;
time = linspace(0,100,100);
x = rand(100,1);
a = NaN(size(time)); % <---- pre-size the a and b arrays
b = NaN(size(time));
hFig = figure(1)
hPlot = plot(a, b, 'r'); % <---- plot the data
axis([0 100 0 1.2])
grid on;
for i = 1:100
a(i) = time(i);
b(i) = x(i);
set(hPlot, 'XData', a, 'YData', b);
pause(0.001)
end

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by