hello everyone .can anyone help me and explain to me this codes for real time ploting????please????

2 ビュー (過去 30 日間)
mark spectre
mark spectre 2022 年 5 月 28 日
コメント済み: dpb 2022 年 5 月 30 日
arduino=serial('COM10','BaudRate',9600);
fopen(arduino);
CM(1)=0;
time(1)=0;
i=1;
tic;
while (toc<=100)
CM(2)=fscanf(arduino,'%f');
time(2)=toc;
figure(1);
grid on;
axis([toc-10, toc+10, 0, 35])
h(i)=plot(time,CM,'b','LineWidth',5);
hold on
CM(1)=CM(2);
time(1)=time(2);
if(i >= 300)
delete(h(i-299));
end
i=i+1;
end
fclose(arduino); % end communication with arduino
  3 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 29 日
Bleh. That code should be rewritten to use animatedline()
mark spectre
mark spectre 2022 年 5 月 29 日
I DONT UNDERSTAND the meaninig of i and i=i+1
and this line
h(i)
if(i >= 300)
delete(h(i-299));
end

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 5 月 29 日
As the code runs, data points come in, at times that are not going to be strictly regular (and might possibly be irregular.)
As each new point comes in, the code draws a line segment from the previous point to the new point, and it shifts the axis limits to show 10 seconds before and after the current time. It records the line handles, and after it has accumulated 300 line handles, as it goes it deletes the one that was created 299 ago. So it creates handle #300, deletes handle #1; creates handle #301, deletes handle #2, and so on.
This is all inefficient, and I would recommend that it be replaced with code that creates an animatedline with a limit of 300 points, and then each time a point comes in, uses addpoints() to add the new point to the animated line.
  6 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 30 日
It is not good code. It would be much better to rewrite with animatedline()
dpb
dpb 2022 年 5 月 30 日
Indeed. My first comment ended with precisely the same conclusion/recommendation.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by