Real Time Data Plot
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Geoff Hayes
el 2 de Abr. de 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
0 comentarios
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!