How to achieve real-time graphics in MATLAB?

11 ビュー (過去 30 日間)
SYED IMTIAZ ALI SHAH
SYED IMTIAZ ALI SHAH 2020 年 2 月 2 日
I created a ball using MATLAB graphics functions. This ball is supposed to follow equations of motion and fall from certain height. The data I generate follows the laws of motion but the ball does not seem( or it looks too slow) to be falling with the speed that we see in real life. It is like if I am seeing this falling object in slow motion. Is it possible to make MATLAB show us the ball going down with exactly the same look and speed as we normally see in real life?

採用された回答

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 2 月 2 日
If you plot your ball in matlab and update the plots there it will never be exactly as fast as a real life example because you have a plotting processing time. If you know the processing time and just skip some frames you may get a reasonable result although a not so smooth one. A solution is to use the videowriter function which has a framing rate that allows you to exactly calculate the time. An example code adpated from the matlab example:
A = rand(300);
v = VideoWriter('newfile.avi');
open(v)
for idx=1:60
writeVideo(v,A)
end
close(v)
The default framerate is 30, so if I have 60 images/plots, the duration of the video will be 2 s. In this way you can exactly calculate how much samples you need and the ration of time needed to end up with a real time plot animation.

その他の回答 (2 件)

Pavel Osipov
Pavel Osipov 2020 年 2 月 2 日
Hello, SYED IMTIAZ ALI SHAH. Please tell me if your ball is moving on the screen. Or do you see a static image? There is a demo in MATLAB - Bouncing Ball. Look. Good luck!
  2 件のコメント
SYED IMTIAZ ALI SHAH
SYED IMTIAZ ALI SHAH 2020 年 2 月 2 日
I moves, but it does not look like it is moving with the real-time speed. Although from data it follows physics correctly.
per isakson
per isakson 2020 年 2 月 2 日

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


Pavel Osipov
Pavel Osipov 2020 年 2 月 2 日
See Matlab help topic: Simulation of a Bouncing Ball.
At Simulink: sldemo_bounce
Good Bye.
BouBall.JPG

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by