How do I create a JPEG file and/or a plot without opening a figure window?

O
Oliviawilliams02 · Aug 6, 2020 · 2.1K views
Question
How do I create a JPEG file and/or a plot without opening a figure window?   I want to directly send a plot to a file. In other words, I want to create a JPEG file using the PRINT command, but I do not want a figure window to open.
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 26, 2026
This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
 
It is possible to create a JPEG without creating a visible figure window. However, you must create a figure to contain the graphics objects. Here is an example of the code to do so:
 
h = figure('visible', 'off')

surf(peaks)

print -djpeg test

close(h)

PLEASE NOTE: This method is currently not available for all image formats. In particular, it does not work for bitmaps, and may not work for other formats as well.

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

Get a Free Consultation or a Sample Assignment Review!