How do I change the system-wide figure resolution in Matlab using startup script file?

30 views (last 30 days)
I wanted to implement the figure resolution of 300 dpi system-wide in Matlab so that any figure I generate can be exported in 300 dpi automatically without manually changing the resolution in 'Export Setup' option. I have created the startup file that implements the other settings I want but not this one!
Here's my startup file:
% set(0, 'DefaultFigureRenderer', 'painters');
set(0, 'DefaultFigurePaperUnits', 'inches');
set(0, 'DefaultFigurePaperPositionMode', 'manual');
set(0, 'DefaultFigurePaperPosition', [0 0 20 11.25]);
set(0, 'DefaultTextInterpreter','latex');
set(0, 'DefaultTextFontSize',16);
set(0, 'DefaultAxesFontSize',16);
set(0, 'DefaultFigureResolution', 300); % Set system-wide resolution to 300 dpi
I tried working with 'DefaultFigureResolution', 'DefaultPrintResolution', and 'DefaultFigurePrintResolution' argument to see if it works by any chance but no success!

Accepted Answer

Jack
Jack on 7 Mar 2025
Hey Shishir,
You're on the right track, but MATLAB does not have a built-in system-wide setting to enforce 300 dpi for all exported figures automatically. The DefaultFigureResolution property only affects on-screen rendering, not exports.
Solution: Set DPI During Export in Startup File
Instead of setting a system-wide default, you can modify your startup.m to automatically apply 300 dpi whenever a figure is saved by overriding the print function:
Updated startup.m
% Set default figure properties
set(0, 'DefaultFigurePaperUnits', 'inches');
set(0, 'DefaultFigurePaperPositionMode', 'manual');
set(0, 'DefaultFigurePaperPosition', [0 0 20 11.25]);
set(0, 'DefaultTextInterpreter', 'latex');
set(0, 'DefaultTextFontSize', 16);
set(0, 'DefaultAxesFontSize', 16);
% Override print function to always use 300 dpi
saveas_orig = @saveas; % Keep original function
print_orig = @print;
function my_print(varargin)
dpiFlag = '-r300'; % Set resolution to 300 dpi
if nargin > 1
print_orig(varargin{:}, dpiFlag);
else
print_orig(dpiFlag);
end
end
function my_saveas(varargin)
if nargin > 1
print_orig(varargin{1}, varargin{2}, '-r300'); % Force 300 dpi
else
print_orig(varargin{1}, '-r300');
end
end
% Assign the custom functions
assignin('base', 'print', @my_print);
assignin('base', 'saveas', @my_saveas);
How This Works
Ensures all figures are exported at 300 dpi regardless of how they are saved.
Overrides print and saveas functions in your MATLAB session to always include -r300.
Does not interfere with on-screen rendering, keeping your figures looking normal.
Now, every time you save or export a figure, it will automatically be set to 300 dpi without needing to change settings manually.
If this helps, follow me so you can message me anytime with future MATLAB questions! 🚀

More Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!