Question
Hi I would like to make the video of a graph which includes the axes labels. It seems that it by default does not. Can someone help me get the whole graph with axes and axes labels in the figure. Here is an example where it does not work as intended since the axes labels are not fully shown. close all; clear all; writerObj = VideoWriter('peaks.avi'); writerObj.FrameRate = 5; open(writerObj); Z = peaks; surf(Z); axis tight set(gca,'nextplot','replacechildren'); set(gcf,'Renderer','zbuffer'); xlabel('x label') ylabel('y label') zlabel('z label') for k = 1:20 surf(sin(2*pi*k/20)*Z,Z) frame = getframe; writeVideo(writerObj,frame); end close(writerObj); winopen('peaks.avi')
Expert Answer
Kshitij Singh
PhD Expert
Answered Aug 29, 2026
I found out how to solve it. The line frame = getframe; is changed to frame = getframe(gcf);
close all; clear all;
writerObj = VideoWriter('peaks.avi');
writerObj.FrameRate = 5;
open(writerObj);
Z = peaks; surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
set(gcf,'Renderer','zbuffer');
xlabel('x label')
ylabel('y label')
zlabel('z label')
for k = 1:20
surf(sin(2*pi*k/20)*Z,Z)
frame = getframe(gcf);
writeVideo(writerObj,frame);
end
close(writerObj);
winopen('peaks.avi')
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related writevideo Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →