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

์กฐํšŒ ์ˆ˜: 30 (์ตœ๊ทผ 30์ผ)
Shishir
Shishir 2025๋…„ 3์›” 7์ผ
์ด๋™: Walter Roberson 2025๋…„ 3์›” 10์ผ
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!

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Jack
Jack 2025๋…„ 3์›” 7์ผ
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! ๐Ÿš€
  ๋Œ“๊ธ€ ์ˆ˜: 1
Shishir
Shishir 2025๋…„ 3์›” 10์ผ
์ด๋™: Walter Roberson 2025๋…„ 3์›” 10์ผ
Thank you so much Jack for this one!

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ถ”๊ฐ€ ๋‹ต๋ณ€ (0๊ฐœ)

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Just for fun์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

์ œํ’ˆ


๋ฆด๋ฆฌ์Šค

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by