Real Time Data Plot

3 ビュー (過去 30 日間)
mehmet kelleci
mehmet kelleci 2020 年 4 月 2 日
回答済み: Geoff Hayes 2020 年 4 月 2 日
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

回答 (1 件)

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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by