MATLAB圖形使用者介面設計GUI
阿新 • • 發佈:2019-01-30
低層繪圖操作
控制代碼 圖形物件的唯一識別符號
gcf ——get current figure
檢視當前影象視窗控制代碼
gca——get current axis
檢視當前座標軸控制代碼
**x=linspace(0,2*pi,30);
y=sin(x);
h0=plot(x,y,'rx');
h1=gcf
h2=gca**
圖形物件屬性操作
屬性設定 set(控制代碼,屬性名1,屬性值1,屬性名2,屬性名2…)
屬性獲得 get V=get(控制代碼,’屬性名’)
PS:1 0 0 代表紅色
圖形物件建立 控制代碼=figure(屬性名1,屬性值1,屬性名2,屬性名2…)
快捷選單
滑鼠指向曲線,單擊右鍵彈出快捷選單。
clc;
clear;
x=0:10;
y=2*x;
hl=plot(x,y);
hc=uicontextmenu; ** 建立快捷選單**
hls=uimenu(hc,'Label','linestyle');
hlw=uimenu(hc,'label','linewidth'); ** 選單選項**
uimenu(hls,'Label','虛線','Call','set(hl,''Linestyle'','':'');'); ** uimenu不加等號**
uimenu(hls,'Label','實線','Call','set(hl,' 'Linestyle'',''-'');'); **set裡兩個單引號!非雙引號**
uimenu(hlw,'Label','加寬','Call','set(hl,''Linewidth'',5);');
uimenu(hlw,'Label','變細','Call','set(hl,''Linewidth'',1);');
set(hl,'uicontextmenu',hc); **將選單和影象建立聯絡**
對話方塊
物件控制代碼=uicontrol(影象視窗控制代碼,屬性1,屬性2…)
**
clc;
clear;
a=uicontrol(gcf,'style','push' ,'position',...
[40,5,100,25],'string','start plot',...%%...連續後面內容,之前要加逗號
'callback','t=0:10;plot(t,sin(t));');
b=uicontrol(gcf,'style','toggle','string','Grid',...
'callback','grid');
%%position不寫即為預設位置 position[左下角為原點的x,y,寬,高]
clc;
clear;
a=uicontrol(gcf,'style','push','position',...
[40,5,100,25],'string','start plot',...
'callback','t=0:2*pi;plot(t,sin(t));');
b=uicontrol(gcf,'style','toggle','string','Grid',...
'callback','grid','position',[170,5,100,25]);
c=uicontrol(gcf,'style','text','string','color options','position',[200,130,150,20]);
red=uicontrol(gcf,'style','radio','string','red','position',[200,100,100,25],...
'callback',['set(red,''value'',1);','set(blue,''value'',0);','set(yellow,''value'',0); ','set(gcf,''color'',''r'');']);
blue=uicontrol(gcf,'style','radio','string','blue','position',[200,75,100,25],...
'callback',['set(blue,''value'',1),','set(red,''value'',0);','set(yellow,''value'',0);','set(gcf,''color'',''b'');']);
yellow=uicontrol(gcf,'style','radio','string','yellow','position',[200,50,100,25],...
'callback',['set(yellow,''value'',1);','set(red,''value'',0);','set(blue,''value'',0);','set(gcf,''color'',''y'');']);
**