Filter löschen
Filter löschen

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

11 Ansichten (letzte 30 Tage)
Lane
Lane am 22 Apr. 2022
Bearbeitet: Lane am 23 Apr. 2022
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.

Akzeptierte Antwort

Chunru
Chunru am 22 Apr. 2022
Bearbeitet: Chunru am 22 Apr. 2022
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 Kommentare
Lane
Lane am 22 Apr. 2022
Bearbeitet: Lane am 22 Apr. 2022
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 am 23 Apr. 2022
Bearbeitet: Lane am 23 Apr. 2022
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');

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by