필터 지우기
필터 지우기

How to get same figure size?

조회 수: 17 (최근 30일)
Rounak Saha Niloy
Rounak Saha Niloy 2023년 10월 5일
댓글: Adam Danz 2023년 10월 5일
I want to save some figures within a loop. The snippet of my code is as follows:
for i=1:10
%%
% Figure Generation Codes
%%
fig = gcf;
ax = gca; set(gca,'FontName','Arial','FontSize',15);
box on;
ax.BoxStyle = 'full';
grid on;
axis tight;
drawnow;
set(fig, 'Units', 'inches');
set(fig, 'Position', [0, 0, 5, 4]);
set(fig, 'PaperSize', [5, 4]);
Filename=strcat(pwd,filesep,'FigX-',num2str(i));
saveas(gcf,Filename,'fig');
print(Filename,'-depsc2','-r300');
end
The problem is, the eps size for each figure is different. I want all of them to be in 5"x4" size. How can I do this? How can I get each eps files to be of same size?
An alternative approach is to go to "export setup" and then manually export each figure. But as I have tons of plots, manually exporting is not a feasible option to me.

답변 (1개)

Adam Danz
Adam Danz 2023년 10월 5일
EPS is a vector format that contains info for every pixel which allows you to scale the size while avoiding pixelation. I wonder how you're loading the eps files and whether there is whitespace that is cropped.
Try exporting the image using exportgraphics. Filename should include the file extension.
Filename = 'myimage.eps';
exportgraphics(gcf,Filename,'ContentType','vector')
  댓글 수: 2
Rounak Saha Niloy
Rounak Saha Niloy 2023년 10월 5일
file sizes are still different
Adam Danz
Adam Danz 2023년 10월 5일
I'm taking stabs in the dark here without the figures or eps files.
Try setting the PaperPositionMode of the figure to auto prior to calling your print command.
set(fig, 'PaperPositionMode','auto')
If that doesn't work, choose 2 figures that are exporing to different sizes and attach the fig and eps files for the two figures (4 files total).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by