概述
在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])
附:saveas
saveasSave figure 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.
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, 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 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.
Remarks
You 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 window's Filemenu uses saveas, limiting the file extensions to m and fig. The Export dialog box you accessfrom the figure window's 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 Also
hgsave, open, print
Printing for related functions
最后
以上就是坚定汉堡为你收集整理的matlab 画图直接存储_Matlab用plot画图后怎么保存图像的全部内容,希望文章能够帮你解决matlab 画图直接存储_Matlab用plot画图后怎么保存图像所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复