$matlab -nodisplay
>>x=0:0.01:4*pi;
>>plot(x, sin(x))
>>print -djpeg -r85 test
如要把图保存成jpeg的格式 的话,可以这样
print -djpeg -r85 jpegtest
ps: print 是 打印命令,这里是打印到文件里
文件名 是jpegtest 你可以用别的文件名代替
-djpeg是格式 d表示device,jpeg是 格式,
-r85 表示像素 85dpi r 表示resolution ,也就是分辨率的第一个字母
打出来如果是1024*768 的显示器,将会大概是500*300的样子(-r85)我没有仔细算过,但是
刚好适应这个博客的尺寸.
最后的结果是得到一个在工作目录下 的 jpegtest.jpg的文件.
当然你有多个图的, 你要先选中它,在执行命令,当然也可用指令来选中它.
===========================================================================
和MATLAB的figure打交道的人可能经常遇到这个问题,
用print或者saveas把figure窗口的内容打印保存成各种格式的图片后,坐标轴区域内的颜色都是白花花的白,而不是自己set后显示在 screen上的结果。
其实解决起来很简单,
在figure窗口的【File | Page Setup...】菜单,Axes and Figures选项卡下
把Background color设成keep screen background color即可,如果是.m中用的话,在print之前加上
set(gcf, 'InvertHardCopy', 'off');语句即可。
这样就可以实现所见即所得的打印了。===========================================================================
Using the Print Command
The print command provides more flexibility in the type of output sent to the printer and allows you to control printing from function and script files. The result can be sent directly to your default printer or stored in a specified output file. A wide variety of output formats, including TIFF, JPEG, and PostScript, is available.
For example, this statement saves the contents of the current figure window as color Encapsulated Level 2 PostScript in the file called magicsquare.eps. It also includes a TIFF preview, which enables most word processors to display the picture.
print -depsc2 -tiff magicsquare.epsTo save the same figure as a TIFF file with a resolution of 200 dpi, use the following command:
print -dtiff -r200 magicsquare.tiffIf you type print on the command line
printthe current figure prints on your default printer.
ref: http://www.mathworks.com/help/techdoc/learn_matlab/f3-1212.html
===========================================================================
Print Syntax printprint('argument1','argument2',...)
print(handle,'filename')
print argument1 argument2 ... argumentn
[pcmd,dev] = printopt
ExamplesSpecifying the Figure to Print
Pass a figure handle as a variable to the function form of print. For example:
h = figure;plot(1:4,5:8)
print(h)
Save the figure with the handle h to a PostScript file named Figure2, which can be printed later:
print(h,'-dps','Figure2.ps')Pass in a file name as a variable:
filename = 'mydata';print(h, '-dpsc', filename);
(Because a file name is specified, the figure will be printed to a file.)
Specifying the Model to PrintPrint a noncurrent Simulink model using the -s option with the title of the window (in this case, f14):
print('-sf14')If the window title includes any spaces, you must call the function form rather than the command form of print. For example, this command saves the Simulink window title Thruster Control:
print('-sThruster Control')To print the current system, use:
print('-s')For information about issues specific to printing Simulink windows, see the Simulink documentation.
Printing Figures at Screen SizeThis example prints a surface plot with interpolated shading. Setting the current figure's (gcf) PaperPositionMode to autoenables you to resize the figure window and print it at the size you see on the screen. See Printing Options and Printing Interpolated Shading with PostScript Drivers for information on the -zbuffer and -r200 options.
surf(peaks)shading interp
set(gcf,'PaperPositionMode','auto')
print('-dpsc2','-zbuffer','-r200')
For additional details, see "Printing Images" in the MATLAB Graphics documentation.
Batch ProcessingYou 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)
print('-dtiff','-r200',fnames{k})
endTiff Preview
The command
print('-depsc','-tiff','-r300','picture1')saves the current figure at 300 dpi, in a color Encapsulated PostScript file named picture1.eps. The -tiff option creates a 72 dpi TIFF preview, which many word processor applications can display on screen after you import the EPS file. This enables you to view the picture on screen within your word processor and print the document to a PostScript printer using a resolution of 300 dpi.
ref: http://www.mathworks.com/help/techdoc/ref/print.html