How do I plot without rendering the figure window and also save the figure to disk in MATLAB 7.10 (R2010a)?

6 views (last 30 days)
I would like to create plots in the background and save them to disk without having them to render at runtime.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Apr 2011
Use the following code to create plots in the background and save them to disk (ex: JPEG Format)
h = figure('Visible','Off'); % Creating a figure and not displaying it
ax = axes; % Create an Axes;
plt = plot(ax,1:10,1:10,'r'); % Plot an arbitrary line in the axes
set(h,'CurrentAxes',ax); % Set current Axes of figure to 'ax'
print(h,'-djpeg','fname.jpeg')% Print the plot to file 'fname.jpeg'
  1 Comment
Samuel Gray
Samuel Gray on 5 Feb 2021
I'm sure there's a property that will allow the jpeg compression (and thus the image-quality) to be set but the easiest way to deal with that is just to use png instead -dpng

Sign in to comment.

More Answers (0)

Products


Release

R2010b

Community Treasure Hunt

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

Start Hunting!