Real Time Data Plot

6 visualizzazioni (ultimi 30 giorni)
mehmet kelleci
mehmet kelleci il 2 Apr 2020
Risposto: Geoff Hayes il 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

Risposte (1)

Geoff Hayes
Geoff Hayes il 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

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by