matlab中matlab figure 标题绘图中的Data Statistics问题!可提高悬赏!

请问一下我这个matlab程序怎样进行数据归一化才能出结果,怕没有人解答先50,有大神愿意帮忙我再增加悬赏_百度知道
请问一下我这个matlab程序怎样进行数据归一化才能出结果,怕没有人解答先50,有大神愿意帮忙我再增加悬赏
T);&gt,P.8759 0; net.7 3. 0 0 1;0 0 1 0 0.5 30;%建立bp神经网路&gt.3 12;92 56 42 35 0,10.8 33; net.7 24;0 0 0 1 0.;&logsig&#39.2 0.2..3063 11; T=[1 0 0 0 0.6 8;0 0 0 1 0. 12.4 8. 0 1 0.6 5. 0 0 0 1;30.2597 25,T. 1 0 0 0..trainparam.5 11;15.trainparam.4;0 0 0 0 1. 60.;tansig&#39..1623 13;%bp网络的仿真&1 0 0 0 0;200 46 16 109 128.9 6.. 1;20;87.9.6 18. 0 0 0 1.8 26.;30..lr=0;&gt.7 0;0 1 0 0 0,P).0032 0;120.8 13;89;0 0 0 0 1];0 1 0 0 0;0 1 0 0 0.4.1101 39.trainparam.7027 1;%参数的设置&gt.7 0..;0 0 1 0 0;3.52;24. 0 1 0 0.;&gt. 1 0 0 0.5.6311;&&gt..1862 31;&gt.8 9.9 10.2081 6.mc=0. 3;1;0 0 1 0 0,&#39.9.;46.2;0 0 0 1 0;44.9 4;&gt.0 24;0 0 0 0 1.5 36.7 9.001.4858;&gt..6 44;84;0 0 0 0 1;1 0 0 0 0.0 10;trainrp&#39.8 0.4058 4;31;33.3 22.2 16.. 0 1 0 0.4 1.0 120;0 0 0 1 0.9117 7;&gt.2 9.2 44.1;0 0 1 0 0.3 6;32.2 13;0 0 1 0 0.7.;42 97 156 598 0.6].1;0 1 0 0 0;33;1 0 0 0 0.show=50;42. 33.4 2.9 0.;&gt.2154; net.6 19. 0 0 0 0;&gt.5 0;0 0 0 1 0.7.6 7;0 0 0 1 0;}.;&98 122 31 292 15.2;0 0 1 0 0.0 24.5 2.0 83; [net tr]=train(46;0 1 0 0 0;7.8259 66.epochs=;12;17.trainparam.5 0..0173 18;72 512 138 1200 5,{&#39.5 18;);57.7 12; net=newff(P.;&gt.8.2 5. 0.0035 27; E=T-A,R); A=sim(net.;0 0 1 0 0.3094;&gt.3 0; 46 0.7 15.5 8..goal=0.5 30;Z=sim(net.;61.6 38,&#39.5157;&&0 0 0 0 1;;&%采用弹性bp算法训练& MSE=mse(E);gensim(net) R=[7.5 2.3 1P=[39
提问者采纳
98 0.6 0.0000
0.94 5.38 3:p=[44.23 0.6以上版本都有再带的归一化函数.85 1.32 2.0000
0.81 2.0075
0;(max(t(i.0000
0.81 2.0112
0.62 44.8269
1:))-min(t(i.0296
0:5T(i.80 0;enddata1=P&#39.32 1.2 0.95 1.2 0.76 3,.58 4.9392
0.73 3.77 0,比如说mapminmax 你的p是5*18矩阵 t是5*5矩阵,你结果输出就是P和T矩阵.0255
0.48 0.0824
0.60]for i=1.0325
0.6 0.21 0.2]t=[46:)))&#47.77 1.13 53.13 0,.98 0.0032
0.247.95 1:5P(i.0102
0.95 0:)));endfor i=1.0106
0:)=(p(i.98 0,你的归一化程序没错:))-min(p(i.0781
0.61 0。我在线 matlab里面7.21 0.44 0.0806
0.253.0283
1.83 1.68 0.53 2.0000
0.8450.0547
0.13 47.8891
0.21 0.6 0.9982
%转置得到18*5data2=T&#39.04 4.98 0:))).94 5.0361
0:)-min(p(i.0580
0.58 4.52 51,我帮你归一化.0703
0.77 1,:)=(t(i.37 2.0081
0你把想要归一化的数据贴上来。.0157
0.39 0.07 2.0605
0.76 3.0093
0.77 1.53 2.48 0.01 0.0284
0。.5355,.0014
0:data1 =
0,我帮你实现了.28 3.94 5.0000
0.29 50.38 3.0582
0,请看结果.0583
0.13 50.68 0.0748
0.2 0.53 2,.64 0.04 3.40 1.0375
0.00 2.0072
0;(max(p(i.7703
0.64 1.77 1.0581
0.64 0.81 2.0070
0.90 2.61 0.0921
0.62 44.04 2.0107
0.62 4.53 2,.94 2.0079
0.03 0.0373
0.72 0.32 2.0000
%转置得到5*5最后结果是,.8803
1.54 4.32 1.6 0.2 0.31 4.0179
0.253,.0106
0.79 1.6 0.80 4.0000
0,.04 3.8281
0.52 53.94 5.0291
0.94 3.85 1.0075
0.44 0.0090
0.73 3.31 4.0106
0.90 44.9985
0.26 3.44 61.0393
0.07 0,.46 4.6846.2 0.0653
0.257.82 3.0227
0.21 0.81 2.7250.30 2:)-min(t(i.0430
0:)))&#47.0605
0,很简单的
朋友,我就是归一化上面的P,T,R,三个矩阵中的数据,。
提问者评价
来自团队:
其他类似问题
为您推荐:
归一化的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁matlab中figure窗口图片保存的问题
matlab中figure窗口图片保存的问题
Figure窗口中的图形导出成jpg格式的图片时,所有的字号都会变大,而且坐标刻度值在有些情况下会改变。我想得到与屏幕上显示完全相同的jpg图形,但又不想用尺寸比较大的bmp.
另:用print生成24位色的bmp时字体也会变大,用saveas生成的bmp不会变大,但只能保存成256色,会丢失颜色。
下面详细说明一下我的要求与解决方法。
由于所绘制的图形用到了colorbar,所以颜色比较多。
1.保存成图片后要求颜色尽量不失真
2.图片要小
3.格式比较常见
4.方法要能够进行批量处理
暂以bmp,jpg,gif三种常见格式的图片结合matlab导出图片的方法进行说明:
1.saveas 能生成bmp,jpg图形
此法生成的bmp只能为256色造成色彩失真。
jpg可以为24位色,但会造成字体显示或坐标显示与屏幕显示不符,字体变大。
2.print 能生成bmp,jpg图形
此法生成的bmp可以为24位色,但和jpg一样都会产生字体和坐标显示与屏幕显示的不符,而且bmp文件比较大。
3.菜单Edit-&Copy Figure拷贝至剪贴版-&保存-&转换为jpg或gif格式
该方法能生成24位色的与屏幕显示效果完全相同的bmp,再由第三方软件转化为jpg或gif格式解决文件大小问题。
转化问题:
(1) jpg格式是有损压缩,在转化后图像质量有所损失。
gif格式是无损压缩,但只支持256色。用一般的格式转换工具将24位色bmp转换为gif格式时会出现色彩失真,该图形中虽colorbar,但所使
用到的颜色种类没有超过256种,所以用Acdsee等专业的转换工具转换后其效果与bmp基本完全一样,效果比jpg好的多,而且文件也比jpg的要
批量处理问题:
(1) Edit -& Copy Figure ,经研究得出Copy Figure菜单的回调函数是
uimenufcn(gcbf,'EditCopyFigure');
我们把gcbf换成gcf即可实现点击当前figure菜单Edit -& Copy Figure
相同的功能,把图片拷贝到剪贴版中。
(2) 从剪贴版获取图片并保存为bmp,此项操作有VB来完成。在VB中获取图片并保存的代码如下:
picBitmap = ClipBoard.GetData(vbCFBitmap)
savepicture picBitmap.picture,"test.bmp"
其中picBitmap为picture控件,将程序编译为exe,在matlab里用system调用
(3)由于没有找到将24位色bmp转换为gif的较好的模块,在生成所有bmp后,用Acdsee批量转换。
用此方法生成了1700多幅gif图片,相应的bmp图片为2.4GB,gif图片仅为40MB左右,而且效果与bmp基本完全一样,肉眼难以辨别。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。当前位置: >>
>> 浏览文章
MATLAB figure中提取数据简单的2个步骤
文章来源:不详 作者:佚名
figure画出来,提取数据有很多好处,方便保存,计算,加工,还可以导入到origin里面画图。
具体的方法就是两部。
第一,找到需要保存的fig对象,命令如下:
h=findobj(gca,'Type','Line');
这里gca代表当前图,line代表图中的线,同样你也可以取坐标轴等等。
第二,提取线中的x,y
x=get(h,'XData');
y=get(h,'YData');
到此,就完成了,当然,我们还可以保存起来,用save命令很方便,具体可以查看
中国高校自动化网 All Rights Reserved.
信息产业部备案号:查看: 12700|回复: 18|关注: 0
请问MATLAB中图和关闭除了一个figure以外其他所有的figure?
请问MATLAB中图和关闭除了一个figure以外其他所有的figure?
能问的再具体些吗?是编程还是在命令区里敲命令?
如果是编程的话,可以用选择语句把要关闭的图的句柄赋给一个向量h,然后用close(h)关闭就行了。
CLOSE(H) closes the window with handle H.
& & CLOSE, by itself, closes the current figure window.
& & CLOSE('name') closes the named window.
& & CLOSE ALL&&closes all the open figure windows.
& & CLOSE ALL HIDDEN&&closes hidden windows as well.
& & STATUS = CLOSE(...) returns 1 if the specified windows were closed
& & and 0 otherwise.
关注者: 7
看不太懂您的問題
delete(findall(0,'type','figure'))
這段程序是同時關閉所有的 figure
回复 2# rendong870311 的帖子
是这样的,我现在用GUI打开了一个Simulink程序,在运行完Simulink程序后需要绘制几个图。第一次运行完程序后,如果手动关掉图就比较麻烦,我想在GUI里把这些图都关掉,用close all的话,连GUI的那个界面都没有了,不知道有没有能够直接关掉除了GUI以外所有figure的语句,谢谢!
回复 4# blandly 的帖子
版主您好!是这样的,我现在用GUI打开了一个Simulink程序,在运行完Simulink程序后需要绘制几个图。第一次运行完程序后,如果手动关掉图就比较麻烦,我想在GUI里把这些图都关掉,用close all的话,连GUI的那个界面都没有了,不知道有没有能够直接关掉除了GUI以外所有figure的语句,谢谢!
回复 4# blandly 的帖子
版主您好!是这样的,我现在用GUI打开了一个Simulink程序,在运行完Simulink程序后需要绘制几个图。第一次运行完程序后,如果手动关掉图就比较麻烦,我想在GUI里把这些图都关掉,用close all的话,连GUI的那个界面都没有了,不知道有没有能够直接关掉除了GUI以外所有figure的语句,谢谢!
回复 4# blandly 的帖子
版主您好!是这样的,我现在用GUI打开了一个Simulink程序,在运行完Simulink程序后需要绘制几个图。第一次运行完程序后,如果手动关掉图就比较麻烦,我想在GUI里把这些图都关掉,用close all的话,连GUI的那个界面都没有了,不知道有没有能够直接关掉除了GUI以外所有figure的语句,谢谢!
回复 4# blandly 的帖子
版主您好!是这样的,我现在用GUI打开了一个Simulink程序,在运行完Simulink程序后需要绘制几个图。第一次运行完程序后,如果手动关掉图就比较麻烦,我想在GUI里把这些图都关掉,用close all的话,连GUI的那个界面都没有了,不知道有没有能够直接关掉除了GUI以外所有figure的语句,谢谢!
回复 1# wanglu1987xy 的帖子
那就可以像我说的那样嘛,产生那些图时获得它们的句柄,
h1=figure(1);
h2=figure(2);
h3=figure(3);
h4=figure(4);
h=[h1 h2 h3 h4];%把那些图的句柄赋给一个向量
在GUI的一个控件的callback函数里写:
这样应该可以达到你要的目的吧。希望能对你有所帮助……
[ 本帖最后由 rendong870311 于
11:43 编辑 ]
站长推荐 /1
Powered by给大家一个非常好用的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
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
colors of these objects. freezeColors works on any graphics
with CData in indexed-color mode: surfaces, images,
scattergroups,
bargroups, patches, etc. It works by converting CData to true-color
based on the colormap active at the time freezeColors is
%&& The original indexed color
data is saved, and can be restored using
unfreezeColors, making the plot once again subject to the colormap
%&& 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); freezeColors
subplot(2,1,2); imagesc(Y); freezeColors etc...
Note: colorbars must also be frozen. Due to Matlab 'improvements'
longer be done with freezeColors. Instead, please
the function CBFREEZE by Carlos Adrian Vargas Aguilera
can be downloaded from the MATLAB File Exchange
h= 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
of your plots.
See also unfreezeColors, freezeColors_pub.html, cbfreeze.
%&& John Iversen () 3/23/05
%&& Changes:
%&& JRI ()
4/19/06&& Correctly handles
scaled integer cdata
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
%&& JRI 4/12/07&
Check for painters mode as Matlab doesn't support rgb in it.
4/9/08&& Fix preserving caxis for
objects within hggroups (e.g. contourf)
4/7/10&& Change documentation for
% 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
%&& 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
appdatacode = 'JRI__freezeColorsData';
[h, nancolor] = checkArgs(varargin);
%gather all children with scaled or indexed CData
cdatah = getCDataHandles(h);
%current colormap
nColors = size(cmap,1);
% convert object color indexes into colormap to true-color data
%& current colormap
for hh = cdatah',
&&& %preserve
parent axis clim
&&& parentAx =
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.
~strcmp(g.Type,'patch'),
cdata = g.CD
cdata = g.FaceVertexCD
&&& %get cdata
mapping (most objects (except scattergroup) have it)
isfield(g,'CDataMapping'),
scalemode = g.CDataM
scalemode = 'scaled';
original indexed data for use with unfreezeColors
size(cdata);
setappdata(hh, appdatacode, {cdata scalemode});
&&& %convert
cdata to indexes into colormap
strcmp(scalemode,'scaled'),
%4/19/06 JRI, Accommodate scaled display of integer cdata:
in MATLAB, uint * double = uint, so must coerce cdata to
Thanks to O Yamashita for pointing this need out
idx = ceil( (double(cdata) - cax(1)) / (cax(2)-cax(1)) *
&&& else %direct
/8/09 in case direct data is non-int (e.g.
freezeColors)
% (Floor mimics how matlab converts data into colormap
% Thanks to D Armyr for the catch
idx = floor(idx);
&&& %clamp to
[1, nColors]
idx(idx&1) = 1;
idx(idx&nColors) = nC
&&& %handle
nans in idx
&&& nanmask =
isnan(idx);
idx(nanmask)=1; %temporarily replace w/ a valid colormap index
true-color data--using current colormap
&&& realcolor =
zeros(siz);
&&& for i =
c = cmap(idx,i);
c = reshape(c,siz);
c(nanmask) = nancolor(i); %restore Nan (or nancolor if
specified)
realcolor(:,:,i) =
&&& %apply new
true-color color data
&&& %true-color
is not supported in painters renderer, so switch out of that
strcmp(get(gcf,'renderer'), 'painters'),
set(gcf,'renderer','zbuffer');
&&& %replace
original CData with true-color data
~strcmp(g.Type,'patch'),
set(hh,'CData',realcolor);
set(hh,'faceVertexCData',permute(realcolor,[1 3 2]))
&&& %restore
clim (so colorbar will show correct limits)
~isempty(parentAx),
set(parentAx,'clim',originalClim)
end %loop on indexed-color objects
============================================================================
% Local functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% getCDataHandles -- get handles of all descendents with indexed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function hout = getCDataHandles(h)
% getCDataHandles& Find all objects with indexed
%recursively descend object tree, finding objects with indexed
% 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),end
ch = get(h,'children');
for hh = ch'
isfield(g,'CData'),&&&&
%does object have CData?
%is it indexed/scaled?
if ~isempty(g.CData) &&
isnumeric(g.CData) &&
size(g.CData,3)==1,
&&&&&&&&&&&
hout = [ hh]; %#ok&AGROW& %yes,
add to list
&&& else %no
CData, see if object has any interesting children
&&&&&&&&&&&
hout = [ getCDataHandles(hh)];
%#ok&AGROW&
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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 axis
if strcmp(get(h,'type'),'axes'),
&&& return
parent = get(h,'parent');
if (strcmp(get(parent,'type'), 'axes')),
getParentAxes(parent);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% checkArgs -- Validate input arguments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [h, nancolor] = checkArgs(args)
% checkArgs& Validate input arguments to
freezeColors
nargs = length(args);
error(nargchk(0,3,nargs,'struct'))
%grab handle from first argument if we have an odd number of
if mod(nargs,2),
~ishandle(h),
error('JRI:freezeColors:checkArgs:invalidHandle',...
&&&&&&&&&&&
'The first argument must be a valid graphics handle (to an
&&& % 4/2010
check if object to be frozen is a colorbar
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.'])
cbfreeze(h);
&&& args{1} =
&&& nargs =
%set nancolor if that option was specified
nancolor = [nan nan nan];
if nargs == 2,
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');
nancolor(nancolor&1) = 1;
nancolor(nancolor&0) = 0;
error('JRI:freezeColors:checkArgs:unrecognizedOption',...
&&&&&&&&&&&
'Unrecognized option (%s). Only ''nancolor'' is
valid.',args{end-1})
function CBH = cbfreeze(varargin)
�FREEZE&& Freezes the colormap of
a colorbar.
%&& SYNTAX:
%&&&&&&&&&&
%&&&&&&&&&&
cbfreeze('off')
%&&&&&&&&&&
cbfreeze(H,...)
CBH = cbfreeze(...);
%&& INPUT:
- Handles of colorbars to be freezed, or from figures to
%&&&&&&&&&&&&
for them or from peer axes (see COLORBAR).
%&&&&&&&&&&&&
DEFAULT: gcf (freezes all colorbars from the current figure)
'off' - Unfreezes the colorbars, other options are:
%&&&&&&&&&&&&&&
%&&&&&&&&&&&&&&
'un'&&& same as
%&&&&&&&&&&&&&&
'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
different COLORMAPs in a single figure, but it fails freezing
COLORBAR. This program handles this problem.
* 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
as normally colorbars when resizing the peer axes. Although,
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
mouse selectable.
* No need to say that CAXIS and COLORMAP must be defined before
this function. Besides, the colorbar location. Anyway, 'off'
'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
colormap gray
title('What...?')
%&& SEE ALSO:
COLORMAP, COLORBAR, CAXIS
FREEZECOLORS by John Iversen
MFILE:&& cbfreeze.m
%&& VERSION: 1.1 (Sep 02, 2009)
href="matlab:web('/matlabcentral/fileexchange/authors/11258')"&download&/a&)
%&& MATLAB:&
7.7.0.471 (R2008b)
%&& AUTHOR:&
Carlos Adrian Vargas Aguilera (MEXICO)
%&& CONTACT:
%&& REVISIONS:
Released. (Jun 08, 2009)
Fixed BUG with image handle on MATLAB R2009a. Thanks to
%&&&&&&&&&&&
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
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
% colorbar handle.
% Set defaults:
'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});
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:
~isempty(getappdata(varargin{1},cbappname))
&&& % The frozen
colorbar is being deleted:
varargin{1};
&&& % The peer
axes is being deleted:
ancestor(varargin{1},{'figure','uipanel'});
&& % The figure is getting
&elseif (gca==varargin{1}
&&&&&&&&&&&&&&&&&&&&
gcf==ancestor(varargin{1},{'figure','uipanel'}))
& % Working as ButtonDownFcn:
& cbfreezedata =
getappdata(varargin{1},cbappname);
& if ~isempty(cbfreezedata)
ishandle(cbfreezedata.ax)
&&& % Turns the
peer axes as current (ignores mouse click-over):
set(gcf,'CurrentAxes',cbfreezedata.ax);
&&& return
&& % Clears application
rmappdata(varargin{1},cbappname)
& H = varargin{1};
&% Checks for normal calling:
&% --------------------------
&% Looks for H:
&if nargin &&
~isempty(varargin{1}) &&
all(ishandle(varargin{1}))
& H = varargin{1};
& varargin(1) = [];
&% Looks for S:
&if ~isempty(varargin)
&& (isempty(varargin{1}) ||
ischar(varargin{1}))
& S = varargin{1};
% Checks S:
if isempty(S)
&S = 'on';
S = lower(S);
iS = strmatch(S,Sopt);
if isempty(iS)
&error('CVARGAS:cbfreeze:IncorrectStringOption',...
& ['Unrecognized ''' S ''' argument.' ])
&S = Sopt{iS};
% Looks for CBH:
CBH = cbfreeze(H); �H = cbhandle(H);
if ~strcmp(S,'del') &&
isempty(CBH)
&% Creates a colorbar and peer axes:
&CBH = colorbar('peer',pax);
&pax = [];
-------------------------------------------------------------------------
-------------------------------------------------------------------------
% Note: only CBH and S are necesary, but I use pax to avoid the use
"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.
& if ~ishandle(pax) % just in case
&& rmappdata(h,cbappname)
&& continue
&elseif isempty(pax) % not generated
double(get(h,'Axes'));& % NEW feature in
&& continue
&% Choose functionality:
& case 'del'
&& % Deletes:
~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','')
isappdata(pax,axappname)
rmappdata(pax,axappname)
strcmp(get(h,'BeingDelete'),'off')
& case {'un','off'}
&& % Unfrozes:
~isempty(cbfreezedata)
delete(h);
set(pax,'DeleteFcn','')
isappdata(pax,axappname)
rmappdata(pax,axappname)
&&& oldunits =
get(pax,'Units');
set(pax,'Units','Normalized')
set(pax,'Position',cbfreezedata.Position)
set(pax,'Units',oldunits)
&&& CBH(icb) =
colorbar(...
'Location',cbfreezedata.Location);
& otherwise % 'on'
&& % Freezes:
&& % Gets colorbar axes
properties:
&& cb_prop& =
&& % Gets colorbar image handle.
Fixed BUG, Sep 2009
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:
&& % 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
&& % NOTE: this is needed because
each time COLORMAP or CAXIS is used,
MATLAB generates a new COLORBAR! This eliminates that
and is the central point on this function.
&& h = axes(...
'Parent'& ,cb_prop.Parent,...
'Units'&& ,'Normalized',...
'Position',cb_prop.Position...
&& % Save location for future
&& cbfreezedata.Location =
&& % Move ticks because IMAGE
draws centered pixels:
&& XLim = cb_prop.XL
&& YLim = cb_prop.YL
isempty(cb_prop.XTick)
&&& X = XLim(1)
+ diff(XLim)/2;
diff(YLim)/(2*length(CData))*[+1 -1];
&& else % isempty(YTick)
Horizontal:
&&& Y = YLim(1)
+ diff(YLim)/2;
diff(XLim)/(2*length(CData))*[+1 -1];
&& % Draws a new RGB image:
image(X,Y,ind2rgb(CData,colormap),...
'Parent'&&&&&&&&&&&
'HitTest'&&&&&&&&&&
,'off',...
'Interruptible'&&&&
,'off',...
'SelectionHighlight','off',...
'Tag'&&&&&&&&&&&&&&
&& % Removes
'...Mode'&& properties:
&& cb_fields =
fieldnames(cb_prop);
indmode&& =
strfind(cb_fields,'Mode');
&& for k=1:length(indmode)
~isempty(indmode{k})
cb_prop = rmfield(cb_prop,cb_fields{k});
&& % Removes special COLORBARs
properties:
&& cb_prop =
rmfield(cb_prop,{...
'CurrentPoint','TightInset','BeingDeleted','Type',...&&&&&&
% read-only
'Title','XLabel','YLabel','ZLabel','Parent','Children',...&
'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)&&&&
set(pax,'DeleteFcn'&&&&&
,@cbfreeze)&&&&
% and again!&
&& % Do not zoom or pan or
setAllowAxesZoom&
setAllowAxesPan&&
setAllowAxesRotate(rotate3d,h,false)
&& % Updates data:
&& CBH(icb) =
&& % Saves data for future
cbfreezedata.pax&&&&&&
&& setappdata(&
h,cbappname,cbfreezedata);
setappdata(pax,axappname,h);
&end % switch
functionality&&
end& % MAIN loop
% OUTPUTS CHECK-OUT
-------------------------------------------------------------------------
% Output?:
if ~nargout
&clear CBH
&CBH(~ishandle(CBH)) = [];
% Returns current axes:
if ishandle(cax)
&set(fig,'CurrentAxes',cax)
% [EOF]&& cbfreeze.m
大家只要把这个.m文件matlab工作文件夹中即可,此函数用来在一个figure上作出多个立体图形。
subplot(1,2,1)
sphere(10)
freezeColors
subplot(1,2,2)
图形如下:
这样在同一个figure中就显示出两个colorbar。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 matlab中figure函数 的文章

 

随机推荐