How can I do a frame-capture style video recording in "Simulink 3D Animation" using matlab?

I'm trying to create video recording of a complicated (30+ nodes) system in "Simulink 3D Animation" that is driven by a matlab script (I don't have simulink). The system is complex enough that I can't simply use the video recording functionality that records what is displayed in the animation viewer because it is too slow and choppy.
Instead, I would prefer to approach the problem similarly to animations in standard matlab plots, in which I use "gcf" to capture the frame, and then when I use "movie2avi" I can dictate the frame rate, such that no matter how long my simulation takes to run each loop, I get an output video with the correct fps.
Alternatively, I'm open to any solution that allows a deterministic selection of frame rate that is not dependent on how fast the computer is able to churn through the model.

1 件のコメント

Nathan Fenner
Nathan Fenner 2014 年 4 月 9 日
One correction: I use getframe(gcf) to capture the frame.

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

回答 (3 件)

Jan Houska
Jan Houska 2014 年 4 月 10 日
To get a single static screenshot of the current Simulink 3D Animation figure, please do
y = capture(vrgcf);
Then, you should be able to create the video stream by using selected screenshots, as needed.

1 件のコメント

Thanks for the help.
I ended up using vr.canvas, and then using getframe(gcf) and that worked pretty well.
I can't get capture(vrgcf) to work.
From a high-level I'm using it as follows:
for i=1:endIndex
%update virtual scene
M(i) = capture(vrgcf);
end
movie2avi(M, 'test');
When I do this, I get the error: "Subscripted assignment dimension mismatch."
I'm having trouble finding the documentation for proper use of this function (and basically all documentation associated with "Simulink 3D Animation").

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

Jan
Jan 2014 年 4 月 15 日
Hi Nathan,
The error message "Subscripted assignment dimension mismatch." comes from the different matrix sizes during the assignment - with (i) subscript the M matrix doesn't get expanded to the assumed size (x,y,i)..
Instead of arranging the matrix M I suggest you to use the VideoWriter object, where you can easily add frames by code like this:
writeVideo(rec_obj, capture(vrgcf))
Best Regards,
Jan
Angelo Yeo
Angelo Yeo 2026 年 2 月 19 日 4:51

0 投票

MATLAB/Simulink from R2025a supports recording Simulink's 3D Animation with sim3d.io.VideoWriter (MATLAB) or Simulation 3D Video Writer block (Simulink).

カテゴリ

ヘルプ センター および File ExchangeAnimation についてさらに検索

質問済み:

2014 年 4 月 9 日

回答済み:

2026 年 2 月 19 日 4:51

Community Treasure Hunt

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

Start Hunting!

Translated by