?? guiplot.m
字號:
function guiplot(action)
%HNDLGRAF Demonstrates Handle Graphics for line plots in MATLAB.
% This window allows you to assemble a string
% of MATLAB commands that results in a plot in
% the axis in the upper left corner.
%
% By playing with the popup menus on the right
% side of the window, you can adjust the line
% style of the plot, the line width, the marker size,
% and the color using Handle Graphics.
%
% The MiniCommand Window in the lower
% right shows the list of commands that create
% the plot. If you like, you can even directly edit
% the commands in the MiniCommand Window.
% Type control-return to execute code in the
% MiniCommand Window.
% Ned Gulley, 6-21-93
% Copyright 1984-2002 The MathWorks, Inc.
% $Revision: 5.12 $ $Date: 2002/04/15 03:32:23 $
if nargin<1,
action='initialize';
end;
if strcmp(action,'initialize'),
oldFigNumber=watchon;
figNumber=figure( ...
'Visible','off', ...
'NumberTitle','off', ...
'Name','圖形與線條對象');
axes( ...
'Units','normalized', ...
'Position',[0.07 0.45 0.60 0.50]);
%===================================
% 代碼窗口
top=0.35;
left=0.05;
right=0.70;
bottom=0.05;
labelHt=0.05;
spacing=0.005;
%建立frame框架
frmBorder=0.02;
frmPos=[left-frmBorder bottom-frmBorder ...
(right-left)+2*frmBorder (top-bottom)+2*frmBorder];
uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.50 0.50 0.50]);
%編輯文本框
labelPos=[left top-labelHt (right-left) labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',[0.50 0.50 0.50], ...
'ForegroundColor',[1 1 1], ...
'String','代碼窗口');
% 可編輯的文本框
mcwPos=[left bottom (right-left) top-bottom-labelHt-spacing];
mcwHndl=uicontrol( ...
'Style','edit', ...
'HorizontalAlignment','left', ...
'Units','normalized', ...
'Max',10, ...
'BackgroundColor',[1 1 1], ...
'Position',mcwPos, ...
'Callback','hndlgraf(''quickeval'')', ...
'String',' % Press buttons at the right for example plots.');
% 保存句柄數據
set(gcf,'UserData',mcwHndl);
%====================================
%按鈕屬性
labelColor=[0.8 0.8 0.8];
top=0.95;
bottom=0.05;
left=0.75;
yInitLabelPos=0.90;
left=0.75;
labelWid=0.20;
labelHt=0.05;
btnWid=0.20;
btnHt=0.05;
%靜態標簽與按鈕之間的距離
btnOffset=0.003;
% 按鈕與與下一個靜態標簽之間的距離
spacing=0.05;
%====================================
% 控制區域的frame
frmBorder=0.02;
yPos=0.05-frmBorder;
frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
h=uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.50 0.50 0.50]);
%====================================
% 線條線型
btnNumber=1;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
labelStr=' 線 型 ';
labelList=' - | --| :| -.| o| x| +| *| .';
cmdList=strvcat( ...
' ',' set(hndl,''LineStyle'',''--'')', ...
' set(hndl,''LineStyle'','':'')', ...
' set(hndl,''LineStyle'',''-.'')', ...
' set(hndl,''Marker'',''o'')', ...
' set(hndl,''Marker'',''x'')', ...
' set(hndl,''Marker'',''+'')', ...
' set(hndl,''Marker'',''*'')', ...
' set(hndl,''Marker'',''.'')');
callbackStr='hndlgraf eval';
% 線型靜態標簽
labelPos=[left yLabelPos-labelHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String',labelStr);
%線型下拉菜單屬性
btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
hndl1=uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList, ...
'Callback',callbackStr, ...
'UserData',cmdList);
%====================================
% 線條的線寬設置
btnNumber=2;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
labelStr='線 寬';
labelList=' 0.5|1|2|3|4';
cmdList=strvcat( ...
' ',' set(hndl,''LineWidth'',1)', ...
' set(hndl,''LineWidth'',2)', ...
' set(hndl,''LineWidth'',3)', ...
' set(hndl,''LineWidth'',4)');
callbackStr='hndlgraf eval';
% 線寬靜態標簽
labelPos=[left yLabelPos-labelHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String',labelStr);
% 線寬下拉菜單屬性
btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
hndl2=uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList, ...
'Callback',callbackStr, ...
'UserData',cmdList);
%====================================
% 線條的標記大小
btnNumber=3;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
labelStr=' 標記大小';
labelList=' 6| 9| 12| 15| 18';
cmdList=strvcat( ...
' ',' set(hndl,''MarkerSize'',9)', ...
' set(hndl,''MarkerSize'',12)', ...
' set(hndl,''MarkerSize'',15)', ...
' set(hndl,''MarkerSize'',18)');
callbackStr='hndlgraf eval';
%標記大小靜態標簽
labelPos=[left yLabelPos-labelHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String',labelStr);
%標記大小下拉式菜單
btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
hndl3=uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList, ...
'Callback',callbackStr, ...
'UserData',cmdList);
%====================================
% 線條顏色設置
btnNumber=4;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
labelStr=' 顏 色';
labelList=' cyan| red| green| blue| magenta| yellow';
cmdList=strvcat( ...
' set(hndl,''Color'',''cyan'')', ...
' set(hndl,''Color'',''red'')', ...
' set(hndl,''Color'',''green'')', ...
' set(hndl,''Color'',''blue'')', ...
' set(hndl,''Color'',''magenta'')', ...
' set(hndl,''Color'',''yellow'')', ...
' set(hndl,''Color'',''white'')');
callbackStr='hndlgraf eval';
% 顏色靜態標簽
labelPos=[left yLabelPos-labelHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String',labelStr);
% 顏色下拉菜單屬性
btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
hndl4=uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList, ...
'Callback',callbackStr, ...
'UserData',cmdList);
%====================================
%相關信息
uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left bottom+2*btnHt+spacing btnWid 2*btnHt], ...
'String','信息', ...
'Callback','hndlgraf(''info'')');
% 關閉按鈕
uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left bottom btnWid 2*btnHt], ...
'String','關閉', ...
'Callback','close(gcf)');
% 不覆蓋圖形
hndlList=[mcwHndl hndl1 hndl2 hndl3 hndl4];
watchoff(oldFigNumber);
set(figNumber,'Visible','on', ...
'UserData',hndlList);
hndlgraf('eval');
elseif strcmp(action,'info'),
helpwin(mfilename)
elseif strcmp(action,'quickeval'),
%執行代碼窗口的代碼程序
hndlList=get(gcf,'UserData');
mcwHndl=hndlList(1);
evalmcw(mcwHndl);
elseif strcmp(action,'eval'),
%組裝和執行完成的命令
hndlList=get(gcf,'UserData');
n=length(hndlList);
mcwHndl=hndlList(1);
evalStr=strvcat(' x=0:0.02:1;',' hndl=plot(x,humps(x));');
for count=2:n,
newStrList=get(hndlList(count),'UserData');
newStrVal=get(hndlList(count),'Value');
newStr=deblank(newStrList(newStrVal,:));
if ~isempty(newStr), evalStr=strvcat(evalStr,newStr); end;
end;
set(mcwHndl,'String',evalStr);
evalmcw(mcwHndl);
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -