MATLAB: Exporting image to bounded pdf

MATLABpdf

If I do this:
set(gcf,'PaperPosition',[0,0,4,3]) print -depsc2 filename.eps
I get a nice image I can include in a latex document. However, if I need to use pdflatex, then I need a pdf image. Now, I know I can use epstopdf to convert the above eps image to pdf, and it works very well, but I wonder if I can do this directly from Matlab. When I try:
set(gcf,'PaperPosition',[0,0,4,3]) print -dpdf filename.pdf
I get a full page, with the image in the lower left corner. Now, I know of tools I can use to crop this result, but I am wondering if I can do this directly in Matlab code.
David Arnold College of the Redwoods Eureka, CA 95501

Best Answer

There are couple of ways to do it
1. plot something do this code
plot([1:10]);
set(gcf, 'PaperPosition', [0 0 5 5]); %Position plot at left hand corner with width 5 and height 5.
set(gcf, 'PaperSize', [5 5]); %Set the paper to have width 5 and height 5.
saveas(gcf, 'test', 'pdf') %Save figure
2. if you have installed latex then pdfcrop is already installed with it so you can do like this.
saveas(gca,'test.pdf');
system('pdfcrop test.pdf test.pdf');
3. you make your own save function and follow 1 or 2 or may be some other procedure to do it.