用print函數保存圖片(Print figure or save to file)
print(figure_handle,‘formats‘,‘-rnumber‘,‘filename‘) %將圖形保存為png格式,分辨率為600的(默認為72),最好指定的分辨率大一點,否則保存圖形的效果較差.
%Save the figure with the handle h to a PostScript file named Figure1, which can be printed later: h = figure; %指定圖片打印figure_handle plot(1:4,5:8) print(h,‘-dpng‘,‘-r200‘,‘Figure1‘) %這三行代碼就夠用了
分辨率-rnumber
Use -rnumber to specify the resolution of the generated output.
To set the resolution(分辨率) of the output file for a built-in MATLAB format, use the -r switch. (For example, -r300 sets the output resolution to 300 dots per inch(每英寸300個點).)
The -r switch is also supported for
——————來自matlab幫助“print”頁中
設置輸出圖片的“圖像縱橫比”
When you set the axes Position to [0 0 1 1] so that it fills the entire figure,
set(gcf,‘PaperPositionMode‘,‘auto‘)%Setting the current figure‘s (gcf) PaperPositionMode to auto enables you to resize the figure window and print it at the size you see on the screen. 舉例:
surf(peaks);shading interp %畫圖 ,shading使圖像美觀axis off %不顯示坐標軸set(gcf,‘PaperPositionMode‘,‘auto‘);%設置圖像縱橫比print(‘-dpng‘,‘-r200‘,‘a‘); %保存圖片,名為a
——來自matlab幫助 Printing Images
Batch Processing(圖片保存“批處理”)filename
You can use the function form of print to pass variables containing file names. For example, this for loop uses file names stored in a cell array to create a series of graphs and prints each one with a different file name:
fnames = {‘file1‘, ‘file2‘, ‘file3‘};for k=1:length(fnames) surf(peaks);shading interp print(‘-dtiff‘,‘-r600‘,fnames{k}) % fnames is a cell of string arrays so, % each element is a stringend
————來自matlab幫助“print”頁末
註:如果你不能調整輸出分辨率和文件格式,可能是"Printing and Exporting without a Display"問題,具體查看幫助“print”頁
輸出圖片的“格式”formats
The following table shows the supported output formats for exporting from figures and the switch settings to use. In some cases, a format is available both as a MATLAB output filter and as a Ghostscript output filter. All formats except for EMF are supported on both Windows and UNIX platforms.
Graphics Format | Bitmap or Vector(矢量) | Print Command Option String | MATLAB or Ghostscript |
---|---|---|---|
BMP monochrome BMP | Bitmap | -dbmpmono | Ghostscript |
BMP 24-bit BMP | Bitmap | -dbmp16m | Ghostscript |
BMP 8-bit (256-color) BMP (this format uses a fixed colormap) | Bitmap | -dbmp256 | Ghostscript |
BMP 24-bit | Bitmap | -dbmp | MATLAB |
EMF | Vector | -dmeta | MATLAB |
EPS black and white | Vector | -deps | MATLAB |
EPS color | Vector | -depsc | MATLAB |
EPS Level 2 black and white | Vector | -deps2 | MATLAB |
EPS Level 2 color | Vector | -depsc2 | MATLAB |
HDF 24-bit | Bitmap | -dhdf | MATLAB |
ILL (Adobe Illustrator) | Vector | -dill | MATLAB |
JPEG 24-bit | Bitmap | -djpeg | MATLAB |
PBM (plain format) 1-bit | Bitmap | -dpbm | Ghostscript |
PBM (raw format) 1-bit | Bitmap | -dpbmraw | Ghostscript |
PCX 1-bit | Bitmap | -dpcxmono | Ghostscript |
PCX 24-bit color PCX file format, three 8-bit planes | Bitmap | -dpcx24b | Ghostscript |
PCX 8-bit newer color PCX file format (256-color) | Bitmap | -dpcx256 | Ghostscript |
PCX Older color PCX file format (EGA/VGA, 16-color) | Bitmap | -dpcx16 | Ghostscript |
PDF Color PDF file format | Vector | -dpdf | Ghostscript |
PGM Portable Graymap (plain format) | Bitmap | -dpgm | Ghostscript |
PGM Portable Graymap (raw format) | Bitmap | -dpgmraw | Ghostscript |
PNG 24-bit | Bitmap | -dpng | MATLAB |
PPM Portable Pixmap (plain format) | Bitmap | -dppm | Ghostscript |
PPM Portable Pixmap (raw format) | Bitmap | -dppmraw | Ghostscript |
SVG Scalable Vector Graphics (For Simulink Models Only) | Vector | -dsvg | MATLAB |
TIFF 24-bit | Bitmap | -dtiff or -dtiffn | MATLAB |
TIFF preview for EPS files | Bitmap | -tiff |
用print函數保存圖片(Print figure or save to file)