figure在matlab中的用法
Matlab的figure中输入上标、下标、特殊符号或字体(转)

Matlab的figure中输入上标、下标、特殊符号或字体(转)展开全文坐标轴标注:1. 控制坐标轴尺度长度:set(gca,'XLim',[-pi/2 pi])2. 定制自己想标注的刻度:(1)set(gca,'XTick',[-pi/2:pi/4:pi])(2)set(gca,'XTickLabel',{'-pi/2' '-pi/4:' '0' 'pi/4' 'pi/2' 'pi*3/4' 'pi'})3. 反转坐标轴:set(gca,'XDir','reverse')4. 上下标及latex公式输下标:_{wb}输上标:^{0.5}输latex公式:text('Interpreter','latex',...'String','$$\int_0^x\!\int_y dF(u,v)$$',...'Position',[.5 .5],...'FontSize',16)在Matlab中输入上标、下标、特殊符号或字体:bf,\it,\rm表示黑体,斜体,正体字符上标用 ^(指数),下标用 _(下划线)调用方式为: ^{任意字符}, _{任意字符}, 注意{}的使用!希腊字母等特殊字符用 \加拼音如:α \alpha β \beta γ \gamma θ \theta Θ \ThetaГ \Gamma δ \delta Δ \Delta ξ iΞ \Xi Ω \Ommigaη \elta ε \epsilong ζ \zeta μ \miu υ \nu τ\tauλ \lamda Λ \Lamda π \pi Π \Pi σ \sigma Σ \Sigmaφ \phi Φ \Phi ψ \psi Ψ \Psi χ \chi ω \ommiga< \leq > \geq 不等于 \neq << \ll >> \gg正负 \pm 左箭头\leftarrow 右箭头\rightarrow 上箭头\uparrow体会以下两例:figure, title('\zeta^{-t}sint');figure, title('x~{\chi}_{\alpha}^{2}(3)');。
matlab中figure的作用

matlab中figure的作用
Matlab中的figure(图形)有如下作用:
一、可视化
1. 为数据提供更易观察的外观:通过将数据可视化,可以让用户更容易查看和理解数据之间的关联。
2. 易于调试:将数据加以可视化,可以有效地帮助用户调试相关代码,检查程序流程,查看变量在代码中的变化情况,并查找出错位置。
二、构造
1. 创建多种多样的图表:Matlab拥有强大的画图功能,可以创建各种类型的图表,例如点图,线图,曲线图,柱形图,极坐标图,子图等,大大方便了科学计算和统计分析。
2. 创建特殊图表:结合应用于学术和工业领域的特定类型的图表(如极限图,平行坐标图,分块图),可以更清晰地表示数据。
三、操作
1. 绘图设置:Matlab拥有强大的图形绘图功能,允许用户自定义各种参数,如线宽,标记,颜色,纹理,特殊符号,填充等,能够有效地提高图表的展示效果。
2. 标签:Matlab的图形可以自动添加各种标签,如图标标题,子标题,图例,坐
标轴。
这些标签可以为图表添加更好的视觉效果,提升可读性,使数据的展示更加直观。
四、分析
1. 数据操纵:Matlab图形可以用于数据操纵,例如对数据进行中值滤波,自适应
滤波,平滑滤波等操作,以便更好地对图表中的数据进行分析和评价。
2. 统计分析:Matlab图形也可以用于统计分析,例如根据绘图得出参数估计值,
进行稳定性分析,拟合曲线,建立多元线性模型等等,来精确分析图表中的数据。
Matlab中保存图像时,图形窗口大小的控制

Matlab中保存图像时,图形窗口大小的控制zz首先要了解的是Matlab是面向对象的。
最高等级的对象是screen,它定义了figure可以用的最大szie。
screen下面是figure。
figue就是你画图的时候跳出来的那个新的对话窗口。
如果figure变化,screen是不会跟着变化的。
但screen变化的话,figure就要跟着变化了。
figure下面是axes。
axes是那个窗口里面你要画的东西。
axes的大小和位置取决于figure,如果你放大缩小figure的大小的话,里面的图线也会跟着变化的。
set(gca,'position',[])因此,set (gca,'position',[0.1,0.1,0.9,0.9] );的作用是:设置坐标轴距离画板(图形窗口figure)边距。
[0.1,0.1,0.9,0.9] 分别为axes在figure中的左边界,下边界,宽度,高度,最小为0,最大为1(左边界,下边界为0,上边界,右边界为1)见下面的例子:-----------------------------------------------------------------------------figureset (gca,'position',[0.1,0.1,0.9,0.9] );x=1:0.1:10;y=sin(x);plot(x,y)-----------------------------------------------------------------------------结果见下图:set(gcf,'position',[])一般matlab绘出来图的框架(图形窗口)大都是正方形或者近似正方形的矩形,能不能画一些扁的矩形呢?使用图形的position属性可以做到。
如set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.32]);的意思是:对gcf的position进行设置。
figure matlab用法

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函数可以关闭指定的图形窗口。
【转载】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的Text对象到句柄值为axes_handle的坐标轴中。
(5) 程序编写GUI步骤:第一步:建立figure对象以作为整个GUI的基础窗口,并设置该窗口的相关属性。
若后续需要建立uimenu,则必须更改窗口的Menubar属性为menubar或figure。
第二步,决定建立需要的axes或uicontrol、uimenu、uicontextmenu对象,并设置相关属性及Callback。
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如何设置)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上作出多个⽴体图形。
post figure在matlab中的用法

post figure在matlab中的用法【原创实用版】目录1.引言2.postfigure 的定义和作用3.如何在 MATLAB 中使用 postfigure4.使用 postfigure 的注意事项5.结论正文【引言】在 MATLAB 中,postfigure 是一个非常实用的命令,它可以帮助用户方便地插入图片和图形。
对于科技论文和报告的撰写,图片和图形的展示是至关重要的。
因此,了解如何在 MATLAB 中使用 postfigure 命令是非常有意义的。
本文将详细介绍 postfigure 的用法和相关注意事项。
【postfigure 的定义和作用】postfigure 是 MATLAB 中的一个命令,它用于在当前的 MATLAB 脚本中插入图片或图形。
与直接使用 plot、scatter 等绘图函数相比,postfigure 提供了一个更便捷的方式来插入图片和图形。
使用postfigure 命令,用户无需关心图片或图形的具体绘制过程,只需指定图片或图形的来源,即可将其插入到 MATLAB 脚本中。
【如何在 MATLAB 中使用 postfigure】要在 MATLAB 中使用 postfigure 命令,首先需要确保已经安装了MATLAB 的图像处理工具箱。
安装完成后,可以按照以下步骤使用postfigure 命令:1.在 MATLAB 命令窗口中,使用 postfigure 命令插入图片或图形。
基本语法如下:```matlabpostfigure("图片或图形的路径");```例如,要插入一张名为“example.png”的图片,可以使用以下命令:```matlabpostfigure("example.png");```2.若要插入多个图片或图形,可以在 postfigure 命令后添加多个参数。
例如:```matlabpostfigure("example1.png", "example2.png");```3.若要指定图片或图形的显示位置,可以使用 postfigure 的选项。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
figure在matlab中的用法
Figure在Matlab中的用法
___________________________
MATLAB(Matrix Laboratory)是一种用于科学计算、可视化和编程的高级语言和交互式环境,它拥有一个强大的图形处理工具包,可以帮助用户创建出各种漂亮的图形。
其中,figure函数尤为重要,下面我们来看看figure在Matlab中的用法。
### 一、figure函数基本用法
Figure函数是Matlab中创建图形的基本函数,它可以创建出一个独立的图形窗口,也可以在已有的图形窗口中创建新的图形。
该函数的基本用法如下:
```
h = figure;
```
在此,h是figure函数的返回值,表示新创建的图形窗口的句柄(handle),可以通过该句柄来操作图形窗口,例如设置图形窗口的大小、位置等。
### 二、figure函数高级用法
除了上面提到的基本用法外,figure函数还具有一些高级用法,例如可以在创建图形窗口时同时设置图形窗口的大小、位置和背景色等。
例如:
```
h = figure('Position', [200, 200, 800, 500], 'Color', 'white');
```
在此,figure函数中添加了一个Position参数,表明新创建的图形窗口位于屏幕上方200像素、左侧200像素处,宽度为800像素、高度为500像素。
同时,添加了一个Color参数,表明新创建的图形窗口的背景色为白色。
### 三、使用figure函数的注意事项
使用figure函数时需要注意以下几点:
- 在使用figure函数时应尽量避免使用全局变量;
- 在使用figure函数时应尽量避免使用循环语句;
- 在使用figure函数时应避免使用不必要的计算;
- 在使用figure函数时应尽量避免使用多余的字符串操作。
### 四、总结
通过上面的介绍,我们可以看到figure函数在Matlab中的重要作用。
它可以帮助用户创建各种漂亮的图形,并且可以通过设定不同的参数来控制图形的样式和外观。
此外,在使用figure函数时还应注意以上提到的几个注意事项。