Les réponses ci-dessus semblent trop compliquées. Cette fonction utilise un handle de figure et une chaîne de caractères pour imprimer le tout dans un fichier pdf sans les énormes marges.
function printpdf(h,outfilename)
set(h, 'PaperUnits','centimeters');
set(h, 'Units','centimeters');
pos=get(h,'Position');
set(h, 'PaperSize', [pos(3) pos(4)]);
set(h, 'PaperPositionMode', 'manual');
set(h, 'PaperPosition',[0 0 pos(3) pos(4)]);
print('-dpdf',outfilename);
Par exemple, pour imprimer le chiffre actuel, vous pouvez l'appeler avec :
printpdf(gcf,'trash')
Cependant, si vous voulez vraiment une figure pdf comme un eps généré par Matlab, c'est-à-dire seulement la coque convexe rectangulaire du graphe (ou de l'ensemble des sous-graphes), voici la version plus sophistiquée :
function printpdf(h,outfilename)
% first use the same non-relative unit system for paper and screen (see
% below)
set(h,'PaperUnits','centimeters');
% now get all existing plots/subplots
a=get(h,'Children');
nfigs=length(a);
% bounds will contain lower-left and upper-right corners of plots plus one
% line to make sure single plots work
bounds=zeros(nfigs+1,4);
bounds(end,1:2)=inf;
bounds(end,3:4)=-inf;
% generate all coordinates of corners of graphs and store them in
% bounds as [lower-left-x lower-left-y upper-right-x upper-right-y] in
% the same unit system as paper (centimeters here)
for i=1:nfigs
set(a(i),'Unit','centimeters');
pos=get(a(i),'Position');
inset=get(a(i),'TightInset');
bounds(i,:)=[pos(1)-inset(1) pos(2)-inset(2) ...
pos(1)+pos(3)+inset(3) pos(2)+pos(4)+inset(4)];
end
% compute the rectangular convex hull of all plots and store that info
% in mypos as [lower-left-x lower-left-y width height] in centimeters
auxmin=min(bounds(:,1:2));
auxmax=max(bounds(:,3:4));
mypos=[auxmin auxmax-auxmin];
% set the paper to the exact size of the on-screen figure using
% figure property PaperSize [width height]
set(h,'PaperSize',[mypos(3) mypos(4)]);
% ensure that paper position mode is in manual in order for the
% printer driver to honor the figure properties
set(h,'PaperPositionMode', 'manual');
% use the PaperPosition four-element vector [left, bottom, width, height]
% to control the location on printed page; place it using horizontal and
% vertical negative offsets equal to the lower-left coordinates of the
% rectangular convex hull of the plot, and increase the size of the figure
% accordingly
set(h,'PaperPosition',[-mypos(1) -mypos(2) ...
mypos(3)+mypos(1) mypos(4)+mypos(2)]);
% print stuff
print('-dpdf',outfilename);
1 votes
Même question : stackoverflow.com/questions/5150802/
2 votes
J'ai pdfcrop dans mon flux de travail pour me débarrasser des espaces après coup. Cela aide aussi beaucoup d'autres programmes qui produisent des PDF sous forme de feuilles de papier entières.
0 votes
Avez-vous appelé le service clientèle ? Matlab est un logiciel commercial coûteux, après tout.