Hello everyone!
I try to make visualisation of the robots motion and record it in video file. The code looks as follows:
%% Visualisation
for ii=1:length(VisualisationArray) center_x = VisualisationArray(ii,1:4:RobotsNum*4); center_y = VisualisationArray(ii,2:4:RobotsNum*4); orientation = VisualisationArray(ii,3:4:RobotsNum*4); [x,y] = triangle(center_x, center_y, orientation);% h.FaceColor = Agent(1).Structure.Position.state(ii);
set(h,'Xdata',x,'Ydata',y); F(ii) = getframe(gcf); pause(0.001)end%% Write a video
writerObj = VideoWriter('myVideo.avi');writerObj.FrameRate = 10;% open the video writer
open(writerObj);% write the frames to the video
for i=1:length(F) % convert the image to a frame
frame = F(i) ; writeVideo(writerObj, frame);end% close the writer object
close(writerObj);
However, if VisualisationArray is too long I recieve the next error message:
Out of memory. Type "help memory" for your options.Error in matlab.graphics.internal.getframeWithDecorations (line 26) u = getFrameImage(c, withDecorations);Error in alternateGetframeError in getframe (line 136)x = alternateGetframe(parentFig, offsetRect, scaledOffsetRect, includeDecorations);Error in Animation (line 17) F(ii) = getframe(gcf);
How to deal with it? Maybe there are another options to record frames video?
Best Answer