figure matlab用法

合集下载

【转载】Matlab中Figure属性的设定

【转载】Matlab中Figure属性的设定

【转载】Matlab中Figure属性的设定GUI常用函数:(1) 利用结构和细胞数组指定一个群组的属性对于一次设置多个对象的属性非常有效,因为该数组可以在任何对象中调用。

下例定义了一个名为active的结构数组,设置特定figure窗口下的unicontrol 对象的Backgroundcolor、enable和Foregroundcolor等属性。

例:active.backgroundcolor=[1 0 0];active.enable = 'on';active.foregroundcolor = [0 1 0];handle = uicontrol(gcf,'style','text','position',[50 50 200 30],'string','以结构数组来设置对象的属性范例');set(handle,active);(2) 也可如下设置多个对象的属性值:set([gcf,gca],'color','r')(3) 补充:gcbf:获得当前正在执行Callback程序的图形对象的父对象句柄值。

gcbo:获得当前正在执行Callback程序的图形对象句柄值。

(4) copyobj:将指定对象由其父对象中复制到另一个父对象中,如copyobj(text_handle,axes_handle)将句柄值为text_handl的T ext 对象到句柄值为axes_handle的坐标轴中。

(5) 程序编写GUI步骤:第一步:建立figure对象以作为整个GUI的基础窗口,并设置该窗口的相关属性。

若后续需要建立uimenu,则必须更改窗口的Menubar属性为menubar或figure。

第二步,决定建立需要的axes或uicontrol、uimenu、uicontextmenu对象,并设置相关属性及Callback。

matlab生成多张figure以及自动保存

matlab生成多张figure以及自动保存

MATLAB生成多张figure以及自动保存最近开始做毕业论文了。

在整理以前做过的诸多论文实验的时候,发现以前用MATLAB写出来的代码是在太混乱了。

算法程序,数据生成,以及图片绘画的.m文件都放在一个目录下。

不要说拿给别人看,就连我自己时间久了都搞不清楚哪种图片是哪个MATLAB程序生成的。

MATLAB没有Visual C++, Java那正规软件开发环境的工程概念,所以人工管理比较麻烦。

一般外人拿到一个论文的实验程序,最简单的,就是拿到一个入口程序,能够自动跑所有的实验程序,并且生成所有的实验图片。

这样,他就至少可以从这个入口程序一步一步跟踪进去,搞明白这一堆.m是什么东西。

那么有个关键问题,如何在一个程序里面生成多个figure呢?查了一下网上,有通过subplot方法实现的。

不过这个方法似乎不太好,因为它其实是将多个figure嵌到一个figure 里面,那么最终还是得一个个分开才能贴到论文里面。

下面是我论文里面的一个例子:function figure_wages()h=figure(1);figure_SLICE();saveas(h,'figure_wages_SLICE.fig');h=figure(2);figure_CARE();saveas(h,'figure_wages_CARE.fig');end这里我用过两个算法在同一块数据上进行训练,最后结果就生成下图两个figure了。

并且调用saveas函数可以实现自动把这两个figure保存到磁盘的.fig文件。

这里的h=figure(1)目的就是制定当前的默认显示的Figure的ID号,并且返回给句柄h。

PS:这里使用的数据都是真实的个人收入数据,其中另外2个维度分别是学历和工作经历。

大家看得出来,这些是在一个平面上的吗?分享到:4楼dragonworrior 2011-04-07 10:05发表[回复]3楼andysun001 2010-03-10 13:56发表[回复]2楼baltam 2009-11-12 21:58发表[回复]其实,如果你是想产生图片,并插入到论文中。

MATLAB生成多张figure以及自动保存

MATLAB生成多张figure以及自动保存

MATLAB生成多张figure以及自动保存最近开始做毕业论文了。

在整理以前做过的诸多论文实验的时候,发现以前用MATLAB写出来的代码是在太混乱了。

算法程序,数据生成,以及图片绘画的.m文件都放在一个目录下。

不要说拿给别人看,就连我自己时间久了都搞不清楚哪种图片是哪个MATLAB程序生成的。

MATLAB没有Visual C++, Java那正规软件开发环境的工程概念,所以人工管理比较麻烦。

一般外人拿到一个论文的实验程序,最简单的,就是拿到一个入口程序,能够自动跑所有的实验程序,并且生成所有的实验图片。

这样,他就至少可以从这个入口程序一步一步跟踪进去,搞明白这一堆.m是什么东西。

那么有个关键问题,如何在一个程序里面生成多个figure呢?查了一下网上,有通过subplot方法实现的。

不过这个方法似乎不太好,因为它其实是将多个figure嵌到一个figure 里面,那么最终还是得一个个分开才能贴到论文里面。

下面是我论文里面的一个例子:function figure_wages()h=figure(1);figure_SLICE();saveas(h,'figure_wages_SLICE.fig');h=figure(2);figure_CARE();saveas(h,'figure_wages_CARE.fig');end这里我用过两个算法在同一块数据上进行训练,最后结果就生成下图两个figure了。

并且调用saveas函数可以实现自动把这两个figure保存到磁盘的.fig文件。

这里的h=figure(1)目的就是制定当前的默认显示的Figure的ID号,并且返回给句柄h。

PS:这里使用的数据都是真实的个人收入数据,其中另外2个维度分别是学历和工作经历。

大家看得出来,这些是在一个平面上的吗?分享到:4楼dragonworrior 2011-04-07 10:05发表[回复]3楼andysun001 2010-03-10 13:56发表[回复]2楼baltam 2009-11-12 21:58发表[回复]其实,如果你是想产生图片,并插入到论文中。

给大家一个非常好用的matlab程序(一个figure中画多幅图,colormap如何设置)

给大家一个非常好用的matlab程序(一个figure中画多幅图,colormap如何设置)

给⼤家⼀个⾮常好⽤的matlab程序(⼀个figure中画多幅图,colormap如何设置)function freezeColors(varargin)% freezeColors Lock colors of plot, enabling multiple colormaps per figure. (v2.3)%% Problem: There is only one colormap per figure. This function provides% an easy solution when plots using different colomaps are desired% in the same figure.%% freezeColors freezes the colors of graphics objects in the current axis so% that subsequent changes to the colormap (or caxis) will not change the% colors of these objects. freezeColors works on any graphics object% with CData in indexed-color mode: surfaces, images, scattergroups,% bargroups, patches, etc. It works by converting CData to true-color rgb% based on the colormap active at the time freezeColors is called.%% The original indexed color data is saved, and can be restored using% unfreezeColors, making the plot once again subject to the colormap and% caxis.%%% Usage:% freezeColors applies to all objects in current axis (gca),% freezeColors(axh) same, but works on axis axh.%% Example:% subplot(2,1,1); imagesc(X); colormap hot; freezeColors% subplot(2,1,2); imagesc(Y); colormap hsv; freezeColors etc...%% Note: colorbars must also be frozen. Due to Matlab 'improvements' this can% no longer be done with freezeColors. Instead, please% use the function CBFREEZE by Carlos Adrian Vargas Aguilera% that can be downloaded from the MATLAB File Exchange% (/matlabcentral/fileexchange/24371)%% h=colorbar; cbfreeze(h), or simply cbfreeze(colorbar)%% For additional examples, see test/test_main.m%% Side effect on render mode: freezeColors does not work with the painters% renderer, because Matlab doesn't support rgb color data in% painters mode. If the current renderer is painters, freezeColors% changes it to zbuffer. This may have unexpected effects on other aspects% of your plots.%% See also unfreezeColors, freezeColors_pub.html, cbfreeze.%%% John Iversen (iversen@) 3/23/05%% Changes:% JRI (iversen@) 4/19/06 Correctly handles scaled integer cdata% JRI 9/1/06 should now handle all objects with cdata: images, surfaces,% scatterplots. (v 2.1)% JRI 11/11/06 Preserves NaN colors. Hidden option (v 2.2, not uploaded)% JRI 3/17/07 Preserve caxis after freezing--maintains colorbar scale (v 2.3)% JRI 4/12/07 Check for painters mode as Matlab doesn't support rgb in it.% JRI 4/9/08 Fix preserving caxis for objects within hggroups (e.g. contourf)% JRI 4/7/10 Change documentation for colorbars% Hidden option for NaN colors:% Missing data are often represented by NaN in the indexed color% data, which renders transparently. This transparency will be preserved% when freezing colors. If instead you wish such gaps to be filled with% a real color, add 'nancolor',[r g b] to the end of the arguments. E.g.% freezeColors('nancolor',[r g b]) or freezeColors(axh,'nancolor',[r g b]),% where [r g b] is a color vector. This works on images & pcolor, but not on% surfaces.% Thanks to Fabiano Busdraghi and Jody Klymak for the suggestions. Bugfixes% attributed in the code.% Free for all uses, but please retain the following:% Original Author:% John Iversen, 2005-10% john_iversen@appdatacode = 'JRI__freezeColorsData';[h, nancolor] = checkArgs(varargin);%gather all children with scaled or indexed CDatacdatah = getCDataHandles(h);%current colormapcmap = colormap;nColors = size(cmap,1);cax = caxis;% convert object color indexes into colormap to true-color data using% current colormapfor hh = cdatah',g = get(hh);%preserve parent axis climparentAx = getParentAxes(hh);originalClim = get(parentAx, 'clim');% Note: Special handling of patches: For some reason, setting% cdata on patches created by bar() yields an error,% so instead we'll set facevertexcdata instead for patches.if ~strcmp(g.Type,'patch'),cdata = g.CData;elsecdata = g.FaceVertexCData;end%get cdata mapping (most objects (except scattergroup) have it)if isfield(g,'CDataMapping'),scalemode = g.CDataMapping;elsescalemode = 'scaled';end%save original indexed data for use with unfreezeColorssiz = size(cdata);setappdata(hh, appdatacode, {cdata scalemode});%convert cdata to indexes into colormapif strcmp(scalemode,'scaled'),%4/19/06 JRI, Accommodate scaled display of integer cdata:% in MATLAB, uint * double = uint, so must coerce cdata to double % Thanks to O Yamashita for pointing this need outidx = ceil( (double(cdata) - cax(1)) / (cax(2)-cax(1)) * nColors);else %direct mappingidx = cdata;/8/09 in case direct data is non-int (e.g. image;freezeColors)% (Floor mimics how matlab converts data into colormap index.)% Thanks to D Armyr for the catchidx = floor(idx);end%clamp to [1, nColors]idx(idx<1) = 1;idx(idx>nColors) = nColors;%handle nans in idxnanmask = isnan(idx);idx(nanmask)=1; %temporarily replace w/ a valid colormap index%make true-color data--using current colormaprealcolor = zeros(siz);for i = 1:3,c = cmap(idx,i);c = reshape(c,siz);c(nanmask) = nancolor(i); %restore Nan (or nancolor if specified)realcolor(:,:,i) = c;end%apply new true-color color data%true-color is not supported in painters renderer, so switch out of that if strcmp(get(gcf,'renderer'), 'painters'),set(gcf,'renderer','zbuffer');end%replace original CData with true-color dataif ~strcmp(g.Type,'patch'),set(hh,'CData',realcolor);elseset(hh,'faceVertexCData',permute(realcolor,[1 3 2]))end%restore clim (so colorbar will show correct limits)if ~isempty(parentAx),set(parentAx,'clim',originalClim)endend %loop on indexed-color objects% ============================================================================ %% Local functions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% getCDataHandles -- get handles of all descendents with indexed CData %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function hout = getCDataHandles(h)% getCDataHandles Find all objects with indexed CData%recursively descend object tree, finding objects with indexed CData% An exception: don't include children of objects that themselves have CData:% for example, scattergroups are non-standard hggroups, with CData. Changing% such a group's CData automatically changes the CData of its children,% (as well as the children's handles), so there's no need to act on them.error(nargchk(1,1,nargin,'struct'))hout = [];if isempty(h),return;endch = get(h,'children');for hh = ch'g = get(hh);if isfield(g,'CData'), %does object have CData?%is it indexed/scaled?if ~isempty(g.CData) && isnumeric(g.CData) && size(g.CData,3)==1,hout = [hout; hh]; %#ok<AGROW> %yes, add to listendelse %no CData, see if object has any interesting childrenhout = [hout; getCDataHandles(hh)]; %#ok<AGROW>endend%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% getParentAxes -- return handle of axes object to which a given object belongs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function hAx = getParentAxes(h)% getParentAxes Return enclosing axes of a given object (could be self)error(nargchk(1,1,nargin,'struct'))%object itself may be an axisif strcmp(get(h,'type'),'axes'),hAx = h;returnendparent = get(h,'parent');if (strcmp(get(parent,'type'), 'axes')),hAx = parent;elsehAx = getParentAxes(parent);end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% checkArgs -- Validate input arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [h, nancolor] = checkArgs(args)% checkArgs Validate input arguments to freezeColorsnargs = length(args);error(nargchk(0,3,nargs,'struct'))%grab handle from first argument if we have an odd number of argumentsif mod(nargs,2),h = args{1};if ~ishandle(h),error('JRI:freezeColors:checkArgs:invalidHandle',...'The first argument must be a valid graphics handle (to an axis)')end% 4/2010 check if object to be frozen is a colorbarif strcmp(get(h,'Tag'),'Colorbar'),if ~exist('cbfreeze.m'),warning('JRI:freezeColors:checkArgs:cannotFreezeColorbar',...['You seem to be attempting to freeze a colorbar. This no longer'...'works. Please read the help for freezeColors for the solution.'])elsecbfreeze(h);returnendendargs{1} = [];nargs = nargs-1;elseh = gca;end%set nancolor if that option was specifiednancolor = [nan nan nan];if nargs == 2,if strcmpi(args{end-1},'nancolor'),nancolor = args{end};if ~all(size(nancolor)==[1 3]),error('JRI:freezeColors:checkArgs:badColorArgument',...'nancolor must be [r g b] vector');endnancolor(nancolor>1) = 1; nancolor(nancolor<0) = 0;elseerror('JRI:freezeColors:checkArgs:unrecognizedOption',...'Unrecognized option (%s). Only ''nancolor'' is valid.',args{end-1})endendfunction CBH = cbfreeze(varargin)�FREEZE Freezes the colormap of a colorbar.%% SYNTAX:% cbfreeze% cbfreeze('off')% cbfreeze(H,...)% CBH = cbfreeze(...);%% INPUT:% H - Handles of colorbars to be freezed, or from figures to search% for them or from peer axes (see COLORBAR).% DEFAULT: gcf (freezes all colorbars from the current figure)% 'off' - Unfreezes the colorbars, other options are:% 'on' Freezes% 'un' same as 'off'% 'del' Deletes the colormap(s).% DEFAULT: 'on' (of course)%% OUTPUT (all optional):% CBH - Color bar handle(s).%% DESCRIPTION:% MATLAB works with a unique COLORMAP by figure which is a big% limitation. Function FREEZECOLORS by John Iversen allows to use % different COLORMAPs in a single figure, but it fails freezing the% COLORBAR. This program handles this problem.%% NOTE:% * Optional inputs use its DEFAULT value when not given or [].% * Optional outputs may or not be called.% * If no colorbar is found, one is created.% * The new frozen colorbar is an axes object and does not behaves% as normally colorbars when resizing the peer axes. Although, some % time the normal behavior is not that good.% * Besides, it does not have the 'Location' property anymore.% * But, it does acts normally: no ZOOM, no PAN, no ROTATE3D and no% mouse selectable.% * No need to say that CAXIS and COLORMAP must be defined before using% this function. Besides, the colorbar location. Anyway, 'off' or% 'del' may help.% * The 'del' functionality may be used whether or not the colorbar(s)% is(are) froozen. The peer axes are resized back. Try:% >> colorbar, cbfreeze del%% EXAMPLE:% surf(peaks(30))% colormap jet% cbfreeze% colormap gray% title('What...?')%% SEE ALSO:% COLORMAP, COLORBAR, CAXIS% and% FREEZECOLORS by John Iversen% at /matlabcentral/fileexchange%%% ---% MFILE: cbfreeze.m% VERSION: 1.1 (Sep 02, 2009) (<a href="matlab:web('/matlabcentral/fileexchange/authors/11258')">download</a>) % MATLAB: 7.7.0.471 (R2008b)% AUTHOR: Carlos Adrian Vargas Aguilera (MEXICO)% CONTACT: nubeobscura@% REVISIONS:% 1.0 Released. (Jun 08, 2009)% 1.1 Fixed BUG with image handle on MATLAB R2009a. Thanks to Sergio% Muniz. (Sep 02, 2009)% DISCLAIMER:% cbfreeze.m is provided "as is" without warranty of any kind, under the% revised BSD license.% Copyright (c) 2009 Carlos Adrian Vargas Aguilera% INPUTS CHECK-IN% -------------------------------------------------------------------------% Parameters:cbappname = 'Frozen'; % Colorbar application data with fields:% 'Location' from colorbar% 'Position' from peer axes befor colorbar% 'pax' handle from peer axes.axappname = 'FrozenColorbar'; % Peer axes application data with frozen% colorbar handle.% Set defaults:S = 'on'; Sopt = {'on','un','off','del'};H = get(0,'CurrentFig');% Check inputs:if nargin==2 && (~isempty(varargin{1}) && all(ishandle(varargin{1})) && ...isempty(varargin{2}))% Check for CallBacks functionalities:% ------------------------------------varargin{1} = double(varargin{1});if strcmp(get(varargin{1},'BeingDelete'),'on')% Working as DeletFcn:if (ishandle(get(varargin{1},'Parent')) && ...~strcmpi(get(get(varargin{1},'Parent'),'BeingDeleted'),'on'))% The handle input is being deleted so do the colorbar:S = 'del';if ~isempty(getappdata(varargin{1},cbappname))% The frozen colorbar is being deleted:H = varargin{1};else% The peer axes is being deleted:H = ancestor(varargin{1},{'figure','uipanel'});endelse% The figure is getting close:returnendelseif (gca==varargin{1} && ...gcf==ancestor(varargin{1},{'figure','uipanel'}))% Working as ButtonDownFcn:cbfreezedata = getappdata(varargin{1},cbappname);if ~isempty(cbfreezedata)if ishandle(cbfreezedata.ax)% Turns the peer axes as current (ignores mouse click-over):set(gcf,'CurrentAxes',cbfreezedata.ax);returnendelse% Clears application data:rmappdata(varargin{1},cbappname)endH = varargin{1};endelse% Checks for normal calling:% --------------------------% Looks for H:if nargin && ~isempty(varargin{1}) && all(ishandle(varargin{1}))H = varargin{1};varargin(1) = [];end% Looks for S:if ~isempty(varargin) && (isempty(varargin{1}) || ischar(varargin{1}))S = varargin{1};endend% Checks S:if isempty(S)S = 'on';endS = lower(S);iS = strmatch(S,Sopt);if isempty(iS)error('CVARGAS:cbfreeze:IncorrectStringOption',...['Unrecognized ''' S ''' argument.' ])elseS = Sopt{iS};end% Looks for CBH:CBH = cbfreeze(H); �H = cbhandle(H);if ~strcmp(S,'del') && isempty(CBH)% Creates a colorbar and peer axes:pax = gca;CBH = colorbar('peer',pax);elsepax = [];end% -------------------------------------------------------------------------% MAIN% -------------------------------------------------------------------------% Note: only CBH and S are necesary, but I use pax to avoid the use of the % "hidden" 'Axes' COLORBAR's property. Why... �% Saves current position:fig = get( 0,'CurrentFigure');cax = get(fig,'CurrentAxes');% Works on every colorbar:for icb = 1:length(CBH)% Colorbar axes handle:h = double(CBH(icb));% This application data:cbfreezedata = getappdata(h,cbappname);% Gets peer axes:if ~isempty(cbfreezedata)pax = cbfreezedata.pax;if ~ishandle(pax) % just in casermappdata(h,cbappname)continueendelseif isempty(pax) % not generatedtrypax = double(get(h,'Axes')); % NEW feature in COLORBARs catchcontinueendend% Choose functionality:switch Scase 'del'% Deletes:if ~isempty(cbfreezedata)% Returns axes to previous size:oldunits = get(pax,'Units');set(pax,'Units','Normalized');set(pax,'Position',cbfreezedata.Position)set(pax,'Units',oldunits)set(pax,'DeleteFcn','')if isappdata(pax,axappname)rmappdata(pax,axappname)endendif strcmp(get(h,'BeingDelete'),'off')delete(h)endcase {'un','off'}% Unfrozes:if ~isempty(cbfreezedata)delete(h);set(pax,'DeleteFcn','')if isappdata(pax,axappname)rmappdata(pax,axappname)endoldunits = get(pax,'Units');set(pax,'Units','Normalized')set(pax,'Position',cbfreezedata.Position)set(pax,'Units',oldunits)CBH(icb) = colorbar(...'peer' ,pax,...'Location',cbfreezedata.Location);endotherwise % 'on'% Freezes:% Gets colorbar axes properties:cb_prop = get(h);% Gets colorbar image handle. Fixed BUG, Sep 2009hi = findobj(h,'Type','image');% Gets image data and transform it in a RGB:CData = get(hi,'CData');if size(CData,3)~=1% It's already frozen:continueend% Gets image tag:Tag = get(hi,'Tag');% Deletes previous colorbar preserving peer axes position: oldunits = get(pax,'Units');set(pax,'Units','Normalized')Position = get(pax,'Position');delete(h)cbfreezedata.Position = get(pax,'Position');set(pax,'Position',Position)set(pax,'Units',oldunits)% Generates new colorbar axes:% NOTE: this is needed because each time COLORMAP or CAXIS is used, % MATLAB generates a new COLORBAR! This eliminates that behaviour % and is the central point on this function.h = axes(...'Parent' ,cb_prop.Parent,...'Units' ,'Normalized',...'Position',cb_prop.Position...);% Save location for future call:cbfreezedata.Location = cb_prop.Location;% Move ticks because IMAGE draws centered pixels:XLim = cb_prop.XLim;YLim = cb_prop.YLim;if isempty(cb_prop.XTick)% Vertical:X = XLim(1) + diff(XLim)/2;Y = YLim + diff(YLim)/(2*length(CData))*[+1 -1];else % isempty(YTick)% Horizontal:Y = YLim(1) + diff(YLim)/2;X = XLim + diff(XLim)/(2*length(CData))*[+1 -1];end% Draws a new RGB image:image(X,Y,ind2rgb(CData,colormap),...'Parent' ,h,...'HitTest' ,'off',...'Interruptible' ,'off',...'SelectionHighlight','off',...'Tag' ,Tag...)% Removes all '...Mode' properties:cb_fields = fieldnames(cb_prop);indmode = strfind(cb_fields,'Mode');for k=1:length(indmode)if ~isempty(indmode{k})cb_prop = rmfield(cb_prop,cb_fields{k});endend% Removes special COLORBARs properties:cb_prop = rmfield(cb_prop,{...'CurrentPoint','TightInset','BeingDeleted','Type',... % read-only'Title','XLabel','YLabel','ZLabel','Parent','Children',... % handles'UIContextMenu','Location',... % colorbars'ButtonDownFcn','DeleteFcn',... % callbacks'CameraPosition','CameraTarget','CameraUpVector','CameraViewAngle',... 'PlotBoxAspectRatio','DataAspectRatio','Position',...'XLim','YLim','ZLim'});% And now, set new axes properties almost equal to the unfrozen% colorbar:set(h,cb_prop)% CallBack features:set(h,...'ActivePositionProperty','position',...'ButtonDownFcn' ,@cbfreeze,... % mhh...'DeleteFcn' ,@cbfreeze) % againset(pax,'DeleteFcn' ,@cbfreeze) % and again!% Do not zoom or pan or rotate:setAllowAxesZoom (zoom ,h,false)setAllowAxesPan (pan ,h,false)setAllowAxesRotate(rotate3d,h,false)% Updates data:CBH(icb) = h;% Saves data for future undo:cbfreezedata.pax = pax;setappdata( h,cbappname,cbfreezedata);setappdata(pax,axappname,h);end % switch functionalityend % MAIN loop% OUTPUTS CHECK-OUT% -------------------------------------------------------------------------% Output?:if ~nargoutclear CBHelseCBH(~ishandle(CBH)) = [];end% Returns current axes:if ishandle(cax)set(fig,'CurrentAxes',cax)end% [EOF] cbfreeze.m⼤家只要把这个.m⽂件matlab⼯作⽂件夹中即可,此函数⽤来在⼀个figure上作出多个⽴体图形。

matlab中快捷键命令组合的使用技巧如下

matlab中快捷键命令组合的使用技巧如下

matlab中快捷键命令组合的使用技巧如下: 1. Ctrl+C 中断正在执行的操作如果程序不小心进入死循环,或者计算时间太长,可以在命令窗口中使用Ctrl+c来中断。

MATLAB这时可能正疲于应付,响应会有些滞后。

2. figure命令新建一个绘图窗口figure 可以打开一个空的绘图窗口,接下的绘图命令可以将图画在它里面,而不会覆盖以前的绘图窗口。

当有多个figure窗口时,在命令窗口中执行如Plot等命令将覆盖当前figure窗口中的对象。

所谓的当前figure窗口,也就是最后一次查看的窗口(可以用命令gcf得到)。

figure(N),将编号为N的窗口置为当前figure,出现在所有窗口的最前面,如果该窗口不存在,则新建一个编号为N的空白figure。

3. 注释掉一段程序:%{、%}。

经典方法是用 if 0,但缺点是不够直观,注释掉的内容仍然保持代码的颜色。

现在可以用 %和{ 的组合。

输入%{后,后面的代码都会变绿,在注释结束的地方再加上 %} 。

也可以选中要注释内容,在右键菜单中选择Comment (Uncomment去掉注释标记),或使用快捷键Ctrl+R。

将光标放在需要注释的行中,按Ctrl+R,将该行变为注释。

取消注释也是一样的,快捷键为Ctrl+T。

4. doc 命令名,打开命令的帮助文档与help命令不同,帮助文档MATLAB Help 中对命令的描述更详细,往往还有一些例子,更便于理解。

5. clc 清屏清除命令窗口中的所有输入和输出信息,不影响命令的历史记录。

6. clear 和clear allclear 变量名:可以清除workspace中的无用的变量,尤其是一些特别大的矩阵,不用时及时清理,可以减少内存占用。

clear all 清除所有的变量,使workspace 一无所有,当重新开始一次算法验证时,最好执行一次,让workspace中的变量一目了然。

7. close all如果开了多个绘图窗口,用这个命令将它们一起关掉。

Matlab自编myfigure函数,快速输出figure图形曲线数据(原创)

Matlab自编myfigure函数,快速输出figure图形曲线数据(原创)

Matlab自编myfigure函数,快速输出figure图形曲线数据L X我们知道Matlab作图功能非常强大,但遗憾的是,Matlab在图形处理方面也有两个很大的不足,其一,Matlab保存的Figure图形,不能像origin图形一样,携带数据并可以在word/ppt/excel里面重新编辑;其二,Matlab没有提供快捷方式使我们能快速地从Figure图形中获取某特定曲线的数据,复制或保存,尽管在一般情况下,我们在WorkSpace中有变量,但是也显得很不方便。

对于第一个不足,由于Matlab的固有属性,我们无法解决,第二个不足,我们可以自编函数解决。

以下,本人新编了一个Figure函数,此函数可对已建立的Figure图形,添加两项一级菜单“输出数据”和“坐标范围”并在一级菜单下各有几项二级菜单,其功能为,1. 对Figure图形中的数据进行输出和保存输出的数据类型可以为xls、txt, 或者将数据重新返回到工作空间;2. 无须打开figure属性,即可快速对figure图形的坐标范围进行设置。

使用方法:将后面蓝色代码全部复制到m文件,并保存为“myfigure”,至于当前路径下。

倾情奉献,如果觉得有参考或使用价值,请下载和评分哦~示例:x=linspace(0,2*pi,100);y1=sin(x);y2=cos(x);figure,plot(x,y1,'r.-',x,y2,'b*')xlabel('x'),ylabel('y')myfigure %运行本段代码,将得到图1图1 运行myfigure对已建的Figure添加功能菜单,见图中绿色椭圆部分1 坐标范围设置,如图2图2 通过单击“坐标范围”菜单下的坐标设置对坐标范围快速设置2 数据输出(至excel或txt或workspace),如图3输出的数据格式,为若干列,一条曲线占两列,分别为x,y,多条则为x,y,x,y。

Matlab中给figure添加图例(legend),标题(title)和颜色(color)

Matlab中给figure添加图例(legend),标题(title)和颜色(color)

Matlab中给figure添加图例(legend),标题(title)和颜⾊(color)在Matlab绘图过程中,尤其是需要将多个图绘制在相同的坐标轴中时,通常需要将不同的曲线设置成为不同的颜⾊。

此外,为了直观,还需要给这张图标增添标题和图例。

这篇⽂章展⽰了在Matlab的绘图窗⼝(figure)中设置曲线颜⾊、添加图例(legend)和标题(title)的⽅法。

在Matlab中,给曲线设定颜⾊可以采⽤plot函数实现。

如下所⽰的语句中:plot(x, y, 'r');是以 x 变量为横坐标,y 变量为纵坐标绘制红⾊曲线。

其中,颜⾊控制由 ‘r’实现。

在Matlab中,预先留了7种颜⾊,分别为‘r’‘g’‘b’‘c’‘m’‘y’‘k’。

如果需要更多的颜⾊调整,可以采⽤‘color’关键词实现,具体语法如下:plot(x, y, 'color', [0.1 0.2 0.3]);其中,出现在‘color’关键词之后的矩阵,控制绘制出来的图像的颜⾊。

当绘制出⼀个曲线之后,可以采⽤ title 函数为绘图增加标题。

具体的代码格式如下所⽰:figure;plot(x, y, 'r')title('这是你绘制的曲线');此外,绘制多条曲线时,为了对曲线进⾏区分,还需要增添图例,可以采⽤legend函数实现。

具体代码格式如下:figure;plot(x, y, 'r')legend('这是你需要的图例');最后,下⾯⼀段代码是将上⾯所有功能集合的演⽰,如下图所⽰:figure;plot([1:10],[5:14]);title('这是标题');hold onplot([1:10],[1:2:20],'color',[0.1 0.7 0.3]);hold offlegend('line 1','line 2');运⾏结果如下:。

matlabfigure用法

matlabfigure用法

matlabfigure用法MATLAB中用于绘图的函数很多,其中,matlabfigure函数是最常用的一种。

本文将围绕matlabfigure的用法进行详细介绍,帮助用户更好地掌握该函数。

一、matlabfigure的作用matlabfigure函数是MATLAB自带的图形函数,它的主要作用是绘制图形。

它可以帮助用户绘制各种类型的图形,包括二维和三维图形。

二、matlabfigure的基本用法matlabfigure函数的使用非常简单。

下面是一个基本的matlabfigure函数的语法:```matlabmatlabfigure();```其中的“()”表示没有任何参数,实际上,这个函数可以接受很多不同的参数,用于调整图形的显示效果。

三、设置图形显示属性matlabfigure函数的一个主要功能是设置图形的显示属性。

可以使用一些可配置的属性来设置图形的线条样式、颜色、标题、坐标轴标签等等。

下面是设置图形属性的一些基本命令:```matlabmatlabfigure('Color', 'white'); % 将背景色设置为白色matlabfigure('LineWidth', 2); % 设置线宽为2matlabfigure('LineStyle', '--'); % 设置线条样式为虚线matlabfigure('Marker', '*'); % 设置数据点标记为星形matlabfigure('Title', '这是一张图表'); % 设置标题matlabfigure('XLabel', '横坐标'); % 设置横坐标标签matlabfigure('YLabel', '纵坐标'); % 设置纵坐标标签```四、设置坐标轴范围matlabfigure函数还可以用于设置坐标轴的范围。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

figure matlab用法
在MATLAB中,figure是一个常用的函数,用于创建新的图形窗口。

以下是figure函数的一些基本用法:
1. 默认用法:
```matlab
figure
```
这将创建一个新的图形窗口,并返回其句柄。

2. 指定图形窗口的名称:
```matlab
figure('Name', 'my_figure')
```
这将创建一个名为"my_figure"的图形窗口。

3. 指定图形窗口的位置和大小:
```matlab
figure('Position', [x, y, width, height])
```
其中,x和y是窗口左上角在屏幕上的坐标,width和height分别是窗口的宽度和高度。

4. 创建多个图形窗口:
```matlab
figure; % 创建第一个图形窗口
figure; % 创建第二个图形窗口
```
每次调用figure函数都会创建一个新的图形窗口。

5. 切换图形窗口:
```matlab
figure(1); % 将当前图形窗口切换为第一个图形窗口figure(2); % 将当前图形窗口切换为第二个图形窗口
```
通过指定图形窗口的句柄,可以切换到指定的图形窗口。

6. 关闭图形窗口:
```matlab
close(h) % h是图形窗口的句柄
```
使用close函数可以关闭指定的图形窗口。

相关文档
最新文档