matlab保存图片的四种方法

上传人:飞*** 文档编号:39929158 上传时间:2018-05-21 格式:DOCX 页数:5 大小:18.63KB
返回 下载 相关 举报
matlab保存图片的四种方法_第1页
第1页 / 共5页
matlab保存图片的四种方法_第2页
第2页 / 共5页
matlab保存图片的四种方法_第3页
第3页 / 共5页
matlab保存图片的四种方法_第4页
第4页 / 共5页
matlab保存图片的四种方法_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《matlab保存图片的四种方法》由会员分享,可在线阅读,更多相关《matlab保存图片的四种方法(5页珍藏版)》请在金锄头文库上搜索。

1、matlabmatlab 保存图片的四种方法保存图片的四种方法1 从菜单保存 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 格式

2、的图片, %文件名为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

3、= 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,file

4、name,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) 附:saveas saveasSave figure

5、or model using specified format Syntax saveas(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.

6、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 Gra

7、phicsppmPortable PixmaptifTIFF image, compressed saveas(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

8、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 ad

9、ditional 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. Remarks You can use open to open files saved using saveas with an m or fig extension. Other forma

10、tsare 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 ExtensionSav

11、e 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

12、 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

13、 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.e

14、ps 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

15、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 Also hgsave, 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); sav

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号