Figura de ahorro de Matlab con tamaño predefinido

I have a figure with 2 plots on it. I am trying to save the figure as a png with a longer width.

a=figure('Name','First Structure');
load C:\Users\William\workspace\P5\FirstAdd.txt
title('First Structure''s Add');
grid on

load C:\Users\William\workspace\P5\FirstContains.txt
title('First Structure''s Contains');
grid on

set(a, 'OuterPosition',rect);
print(a,'-dpng','First Structure.png');

In the last 3 lines I set the figure window such that the 2 plots are wide enough. However, when I try to save the figure, the image is its default size in which the plots are squished.

¿Qué me estoy perdiendo?

preguntado el 28 de agosto de 11 a las 02:08

2 Respuestas

Al OuterPosition propiedad de la figura only changes where the figure window is on the screen; it doesn't change how it will print.

Matlab uses the PaperSize, PaperUnits, PaperPosition and similar figure properties when "printing" a figure, even when they don't really make sense, such as when producing a bitmap file. (Settings PaperUnits a pixels would be logical, but it doesn't work.)

The procedure for getting a particular image size in píxeles es establecer PaperPosition to some size in pulgadas (or another physical unit) and then specify the desired resolución in dots per inch using the -r opción de print:

r = 150; % pixels per inch
set(gcf, 'PaperUnits', 'inches', 'PaperPosition', [0 0 1080 480]/r);
print(gcf,'-dpng',sprintf('-r%d',r), 'bar.png');

Some of these peculiarities are discussed in the help for the print función.

También puedes probar el -r0 option which tells Matlab to use the display resolution.

Respondido 28 ago 11, 09:08

Following @nibot's example, I wrote the following function:

function save_as_png(handle, filename, dpi, width, height);
    set(handle, 'PaperUnits', 'inches', 'PaperPosition', [0 0 width height] / dpi);
    print(handle, '-dpng', ['-r' num2str(dpi)], filename);

Respondido 22 ago 13, 02:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.