I’m trying to print my figure in MATLAB, but it keeps screwing up and I have no idea why.
opslaan = figure(1);
plot(1:handles.aantal,handles.nauw,'-r','LineWidth',1.5);
xlabel(gca,sprintf('Framenummer (%g ms per frame)',60/handles.aantal));
ylabel(gca,'dB');
set(gca,'YGrid','on');
yAsMax = ceil( ceil(max(handles.nauw)) / 2) * 2;
axis([0 handles.aantal 0 yAsMax]);
pause(1);
print -dpng image.png
The first line is just plotting the data on my figure, then labeling x and y, turning on grid and calculating the y-axis like I want it. This all works great and MATLAB shows it like I want it in the figure window. When saving to .png / .jpeg / .eps, it goes wrong and only prints the bottom left corner (473×355 pixels), the rest just disappeared.
When exporting manually via File -> Save As, it works correctly.
How do I fix it?
Try using the following line instead of the print line you already have.
print(opslaan, ‘-dpng’, ‘image.png’)
Another option would be to look into
imwrite.