Real Time Data Plot
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Geoff Hayes
2020 年 4 月 2 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!