Rapid image capture for video assembly?

I am trying to make a video using the code given below. It is very slow. A test run took circa 2 hrs 20 mins. I would like improve the speed. Usually, I would not use "cla" which increases the speed greatly but in this case the memory demands are too high for my available RAM. (Note the total number of points to plot is 10^6 and the number of frames is 2000, much higher than I usually have to contend with.) I compared use of "cla" with closing the figure and opening a new one for each frame and "cla" is faster by hours. Turning the figure visibility off leads to no frames being captured. Any ideas for speed gains?
n = 10^6; %Number of points
intvl = 500; %Number of points added per frame of video
mars = jet(n);
fRate = 60;
xn = randn(1,n);
yn = randn(1,n);
[sxn, I] = sort(xn);
syn = yn(I);
gtex = 'Some_';
atex = 'parameter_';
btex = 'values_';
ctex = 'go_';
dtex = 'here';
para = [gtex atex btex ctex dtex];
pos = [218 102 1332 798]; % [x y width height]
vidObj = VideoWriter(para,'MPEG-4');
vidObj.FrameRate = fRate;
vidObj.Quality = 100;
open(vidObj);
tic
figure(WindowState="maximized");
for q=1:intvl:n+1
scatter(sxn(1:q-1),syn(1:q-1),1,mars((1:q-1),:))
set(gcf,'ToolBar','none');
set(gca,'color',[0 0 0])
set(gca,"XTick",[])
set(gca,"YTick",[])
set(gca,"ZTick",[])
axis equal
clim([min(sxn) max(sxn)])
drawnow
currFrame = getframe(gcf,pos);
writeVideo(vidObj,currFrame);
cla
end
close(vidObj);
toc

 채택된 답변

Image Analyst
Image Analyst 2026년 7월 15일 13:49

0 개 추천

Perhaps try putting all your calls to set in a single call to set() rather than a bunch of separate calls.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

릴리스

R2024b

질문:

2026년 7월 14일 12:34

답변:

2026년 7월 15일 13:49

Community Treasure Hunt

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

Start Hunting!

Translated by