MATLAB: Problems saving plot in 300 dpi

dpimatlab printpngsaving plots

Hi,
I am trying to find a decent way to make my matlab script automatically save plots into .pngs without using the export_fig function (I am not able to use it for my purposes). I recognized that when I use my way, there is an issue with the labels. If I save my png in 100dpi I can read it. My goal is it to save it with 300 dpi though. But when I do, sometimes the label gets just a grey bar with no text in it. It depends on the plot I want to save though. So sometimes I can save it in 300 dpi but sometimes there is this grey bar. Does anyone know how to solve this? Did anyone ever had the same problem?
Thank you
My code:
fig = gcf;
fig.PaperUnits = 'inches';
fig.PaperPosition = [0 0 18 9];
fig.PaperPositionMode = 'manual'
fname = ['Energy_resolved_',num2str(i).'_2'];
set(gcf,'Visible','off');
print(['-f',],'-dpng','r0','-r300',fname);
close(gcf);

Best Answer

print(gcf,'test.png','-dpng','-r300');
Related Question