matlab保存图片四种方法.doc_第1页
matlab保存图片四种方法.doc_第2页
matlab保存图片四种方法.doc_第3页
matlab保存图片四种方法.doc_第4页
matlab保存图片四种方法.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

matlab保存图片四种方法1 从菜单保存 回目录可以保存为fig,eps,jpeg,gif,png,bmp等格式。2 复制粘贴 回目录edit-copy figure,再粘贴到其他程序,如word3 saveas函数 回目录saveas(gca,filename,fileformat)不过此函数不好用常常出错4 print函数 x=-pi:2*pi/300:pi; y=sin(x); plot(x,y); print(gcf,-dpng,abc.png) % 保存为png格式的图片。 pwdD:Matlabwork dir % 现在到 D:Matlabwork 应该能找到图片 abc.png 了 figure(2) % 新建一个句柄为2的图形窗口。 plot(x,cos(x); % 在句柄为2的图形窗口上画图。 grid print(2,-djpeg,D:abc.jpeg); %将句柄为2的图形保存为jpeg/jpg格式的图片, %文件名为D:abc.jpeg。4.2 用法:print(图形句柄,存储格式,文件名); 回目录图形句柄,如果图形窗口标题栏是“Figure 3”,则句柄就是3.用gcf可以获取当前窗口句柄。 指定存储格式。常用的有: png格式:-dpng (推荐这一种,与bmp格式一样清晰,文件也不大) jpeg: -djpeg(文件小,较清晰) tiff: -dtiff bmp: -dbitmap(清晰,文件极大) gif: -dgif(文件小但不清晰) 文件名 在matlab中自动保存plot图像的程序Step 1. 先使所画的图最大化,即占满整个屏幕scrsz = get(0,ScreenSize);figure1=figure(Position,0 30 scrsz(3) scrsz(4)-95);或者(下面这种情况会把windows系统下面的任务栏也保存到图片中,不太好)scrsz = get(0,ScreenSize);figure1=figure(Position,0 0 scrsz(3) scrsz(4)-66);% Step 2. 生成数据并画图x=rand(100,1);plot(x);saveas(gcf,filename,bmp);saveas(gcf,filename,emf);saveas(gcf,filename,jpg);% Step 3. 清理现场clear all; clc; close all;下面的代码可以创建一个大小为整个屏幕的四分之一,位置在屏幕在左上角的一个figure对像,使用root对象的ScreenSize属性来取得屏幕的尺寸,ScreenSize是由四个元素组成的数据:left,bottom,width,height)。scrsz = get(0,ScreenSize);figure2=figure(Position,1 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2)附:saveassaveasSave figure or model using specified format Syntaxsaveas(h,filename.ext)saveas(h,filename,format)Descriptionsaveas(h,filename.ext) saves the figure or model with the handle h to the file filename.ext.The format of the file is determined by the extension, ext. Allowable values for ext arelisted in this table.ext ValueFormataiAdobe Illustrator 88bmpWindows bitmapemfEnhanced metafileepsEPS Level1figMATLAB figure (invalid for Simulink models)jpgJPEG image (invalid for Simulink models)mMATLAB M-file (invalid for Simulink models)pbmPortable bitmappcxPaintbrush 24-bitpgmPortableGraymappngPortable Network GraphicsppmPortable PixmaptifTIFF image, compressedsaveas(h,filename,format) saves the figure or model with the handle h to the file calledfilename using the specified format. The filename can have an extension, but the extension isnot used to define the file format. If no extension is specified, the standard extensioncorresponding to the specified format is automatically appended to the filename. Allowable values for format are the extensions in the table above and the device typessupported by print. The print device types include the formats listed in the table ofextensions above as well as additional file formats. Use an extension from the table above orfrom the list of device types supported by print. When using the print device type to specifyformat for saveas, do not use the prefixed -d. RemarksYou can use open to open files saved using saveas with an m or fig extension. Other formatsare not supported by open. The Save As dialog box you access from the figure windows Filemenu uses saveas, limiting the file extensions to m and fig. The Export dialog box you accessfrom the figure windows File menu uses saveas with the format argument. ExamplesExample 1: Specify File ExtensionSave the current figure that you annotated using the Plot Editor to a file named pred_preyusing the MATLAB fig format. This allows you to open the file pred_prey.fig at a later timeand continue editing it with the Plot Editor. saveas(gcf,pred_prey.fig)Example 2: Specify File Format but No ExtensionSave the current figure, using Adobe Illustrator format, to the file logo. Use the aiextension from the above table to specify the format. The file created is logo.ai. saveas(gcf,logo, ai)This is the same as using the Adobe Illustrator format from the print devices table, which is-dill; use doc print or help print to see the table for print device types. The file createdis logo.ai. MATLAB automatically appends the ai extension for an Illustrator format filebecause no extension was specified. saveas(gcf,logo, ill)Example 3: Specify File Format and ExtensionSave the current figure to the file star.eps using the Level 2 Color PostScript format. If youuse doc print or help print, you can see from the table for print device types that the devicetype for this format is -dpsc2. The file created is star.eps. saveas(gcf,star.eps, psc2)In another example, save the current model to the file trans.tiff using the TIFF format withno compression. From the table for print device types, you can see that the device type forthis format is -dtiffn. The file created is trans.tiff. saveas(gcf,trans.tiff, tiffn)See Alsohgsave, open, print Printing for related functions在matlab中自动保存plot图像的程序Step 1. 先使所画的图最大化,即占满整个屏幕scrsz = get(0,ScreenSize);figure1=figure(Position,0 30 scrsz(3) scrsz(4)-95);或者(下面这种情况会把windows系统下面的任务栏也保存到图片中,不太好)scrsz = get(0,ScreenSize);figure1=figure(Position,0 0 scrsz(3) scrsz(4)-66);% Step 2. 生成数据并画图x=rand(100,1);plot(x);saveas(gcf,filename,bmp);saveas(gcf,filename,emf);saveas(gcf,filename,jpg);% Step 3. 清理现场clear all; clc; close all;下面的代码可以创建一个大小为整个屏幕的四分之一,位置在屏幕在左上角的一个figure对像,使用root对象的ScreenSize属性来取得屏幕的尺寸,ScreenSize是由四个元素组成的数据:left,bottom,width,height)。scrsz = get(0,ScreenSize);figure2=figure(Position,1 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2)附:saveassaveasSave figure or model using specified format Syntaxsaveas(h,filename.ext)saveas(h,filename,format)Descriptionsaveas(h,filename.ext) saves the figure or model with the handle h to the file filename.ext.The format of the file is determined by the extension, ext. Allowable values for ext arelisted in this table.ext ValueFormataiAdobe Illustrator 88bmpWindows bitmapemfEnhanced metafileepsEPS Level1figMATLAB figure (invalid for Simulink models)jpgJPEG image (invalid for Simulink models)mMATLAB M-file (invalid for Simulink models)pbmPortable bitmappcxPaintbrush 24-bitpgmPortableGraymappngPortable Network GraphicsppmPortable PixmaptifTIFF image, compressedsaveas(h,filename,format) saves the figure or model with the handle h to the file calledfilename using the specified format. The filename can have an extension, but the extension isnot used to define the file format. If no extension is specified, the standard extensioncorresponding to the specified format is automatically appended to the filename. Allowable values for format are the extensions in the table above and the device typessupported by print. The print device types include the formats listed in the table ofextensions above as well as additional file formats. Use an extension from the table above orfrom the list of device types supported by print. When using the print device type to specifyformat for saveas, do not use the prefixed -d. RemarksYou can use open to open files saved using saveas with an m or fig extension. Other formatsare not supported by open. The Save As dialog box you access from the figure windows Filemenu uses saveas, limiting the file extensions to m and fig. The Export dialog box you accessfrom the figure windows File menu uses saveas with the format argument. ExamplesExample 1: Specify File ExtensionSave the current figure that you annotated using the Plot Editor to a file named pred_preyusing the MATLAB fig format. This allows you to open the file pred_prey.fig at a later timeand continue editing it with the Plot Editor. saveas(gcf,pred_prey.fig)Example 2: Specify File Format but No ExtensionSave the current figure, using Adobe Illustrator format, to the file logo. Use the aiextension from the above table to specify the format. The file created is logo.ai. saveas(gcf,logo, ai)This is the same as using the Adobe Illustrator format from the print devices table, which is-dill; use doc print or help print to see t

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论