Prev: "Model-Based Design for DO-254"- ONE webinar session only- July 22nd @ 10:00am EDT
Next: parfor reference to a cleared variable
From: Enrico on 19 Jul 2010 16:10 I am trying to save a figure at a specific size/resolution but and seeing strange behavior. imagesc(blah); set(gcf,'units','pixel'); set(gcf,'position',[0,0,960,960]); set(gcf,'papersize',[960,960]); saveas(gcf,'image.jpg'); image.jpg will end up being 1500x1500. if I do 614x614, i think then it comes pretty close to 960x960, but that doesnt seem like the right way to output at the size i want.
From: matt dash on 19 Jul 2010 16:42 "Enrico " <en(a)rcsnetwork.com> wrote in message <i22bf1$fit$1(a)fred.mathworks.com>... > I am trying to save a figure at a specific size/resolution but and seeing strange behavior. > > imagesc(blah); > set(gcf,'units','pixel'); > set(gcf,'position',[0,0,960,960]); > set(gcf,'papersize',[960,960]); > saveas(gcf,'image.jpg'); > > image.jpg will end up being 1500x1500. > > if I do 614x614, i think then it comes pretty close to 960x960, but that doesnt seem like the right way to output at the size i want. Here's some canned code i use for exporting figures: rez=1200; %resolution (dpi) of final graphic f=gcf; %f is the handle of the figure you want to export figpos=getpixelposition(f); %dont need to change anything here resolution=get(0,'ScreenPixelsPerInch'); %dont need to change anything here set(f,'paperunits','inches','papersize',figpos(3:4)/resolution,'paperposition',[0 0 figpos(3:4)/resolution]); %dont need to change anything here path='C:\Documents and Settings\yournamehere\Desktop\'; %the folder where you want to put the file name='filename.png'; %what you want the file to be called print(f,fullfile(path,name),'-dpng',['-r',num2str(rez)],'-opengl') %save file I like print instead of saveas. Just change the -dpng to the file format you want (read the help file for print). You might also want to change -opengl to -zbuffer If by "resolution" you mean "dimensions" then use rez = get(0,'screenpixelsperinch'); ....which is probably 96... and it should behave the way you want it to. If you want to stick with your method, try also changing the paperunits property to pixels and maybe it'll work.
From: Enrico on 19 Jul 2010 17:31 "matt dash" <n.a(a)mail.com> wrote in message <i22das$gmb$1(a)fred.mathworks.com>... > > > Here's some canned code i use for exporting figures: > > rez=1200; %resolution (dpi) of final graphic > f=gcf; %f is the handle of the figure you want to export > figpos=getpixelposition(f); %dont need to change anything here > resolution=get(0,'ScreenPixelsPerInch'); %dont need to change anything here > set(f,'paperunits','inches','papersize',figpos(3:4)/resolution,'paperposition',[0 0 figpos(3:4)/resolution]); %dont need to change anything here > path='C:\Documents and Settings\yournamehere\Desktop\'; %the folder where you want to put the file > name='filename.png'; %what you want the file to be called > print(f,fullfile(path,name),'-dpng',['-r',num2str(rez)],'-opengl') %save file > > I like print instead of saveas. Just change the -dpng to the file format you want (read the help file for print). You might also want to change -opengl to -zbuffer > > If by "resolution" you mean "dimensions" then use rez = get(0,'screenpixelsperinch'); > ...which is probably 96... and it should behave the way you want it to. > > If you want to stick with your method, try also changing the paperunits property to pixels and maybe it'll work. Same result. I tried that exactly. Yes I get 96 screen ppi. I want a 960x960 so I set papersize and paperposition to 10x10. My resulting file is 1500x1500. No idea why.
From: matt dash on 19 Jul 2010 19:07 > Same result. I tried that exactly. Yes I get 96 screen ppi. I want a 960x960 so I set papersize and paperposition to 10x10. My resulting file is 1500x1500. No idea why. Ah, ok. When I use saveas I also get 1500x1500... if you look at the source code for saveas all it does it call print, but it doesnt specify the resolution. The help for the print command says resolution defaults to 150dpi, hence 1500x1500. Looks like the method i pasted above (calling print while specifying the resolution is the only way to get it at 96dpi.)... you really only need the last line of what i pasted, just put in -r96
From: Enrico on 20 Jul 2010 08:41
"matt dash" <n.a(a)mail.com> wrote in message <i22lqn$c27$1(a)fred.mathworks.com>... > Ah, ok. When I use saveas I also get 1500x1500... if you look at the source code for saveas all it does it call print, but it doesnt specify the resolution. The help for the print command says resolution defaults to 150dpi, hence 1500x1500. Looks like the method i pasted above (calling print while specifying the resolution is the only way to get it at 96dpi.)... you really only need the last line of what i pasted, just put in -r96 Thanks, I did try print, but not the -r96. That did the trick. |