필터 지우기
필터 지우기

I want to create printouts with exact sizes (1=1")

조회 수: 11 (최근 30일)
Lane
Lane 2022년 4월 22일
편집: Lane 2022년 4월 23일
I somewhat frequently use Matlab to create images of things I want to build (as in build a physical object). In some situations, it would be useful to create a figure that's the exact size of the object I want to build. I can create, for example, a box that's 1x1 in the dimensions of my figure, but by the time I go through saving and then printing with all the attendant options, the "size" gets changed multiple times.
I'm about to write a function that creates a figure of a specified size and then exports that figure to a file and then print that file and then measure 1 unit with a ruler and then keep adjusting the parameters until I get it approximately right, but if there's a cleaner way to do it I'd like to hear it.

채택된 답변

Chunru
Chunru 2022년 4월 22일
편집: Chunru 2022년 4월 22일
g = figure;
g.Units = 'inches';
g.Position = [1 2 3 3]; % 3 by 3 inches
plot(rand(10,1));
saveas('test.pdf');
% You can measure the figure size in pdf to be the one you specified (outer
% box including the axis labels)
% If you want to set the axes size
%{
a = gca;
a.Units = "inches";
g.Position = [1 2 3 3]; % adjust these values
%}
  댓글 수: 6
Lane
Lane 2022년 4월 22일
편집: Lane 2022년 4월 22일
You're not really suggesting that I was actually producing a 3" square and mismeasuring it as 2.34", are you?
The confusion was caused my me, I think, because when I said I wanted to create a "figure that's the exact size of the object I want to build" I wasn't confusing figures and axes, but I was using "figure" to mean "the paper version of the physical object I want to create". The problem is that almost every word I could use to describe that (including "object" for that matter) has a specific meaning in Matlab.
Anyway, Chunru's second variant (in which the printed graphics are the size of the real world) is exactly what I needed. Thanks.
Lane
Lane 2022년 4월 23일
편집: Lane 2022년 4월 23일
Actually, there turned out to be one more step. Like I said in the original post, my goal was not to make the (matlab) figure or axes a certain size, but to make the actual plot units true to life. In Chunru's solution, the axes were indeed two inches, but those two inches contained 10 units and I needed them to contain two units (so one unit is one inch). I modified Chunru's code thusly:
figure(1); clf;
a = gca;
a.Units = "inches";
a.Position = [1 2 3 3];
plot([0 3],[0 3])
axis tight
grid on
saveas(gcf,'~/test2.pdf');

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by