160 likes | 296 Vues
This guide covers how to design graphical user interfaces (GUIs) using MATLAB, focusing on handling graphics components and modifying properties. Key topics include creating GUI controls like pushbuttons, edit fields, and popups, as well as manipulating graphical properties for better visualization. Learn to use 'uicontrol', 'axes', and 'figure' functions to create responsive designs for advanced applications such as PID control software. Example code snippets illustrate how to set up a GUI and customize it through callbacks for interactive experiences.
E N D
Unit 5 Graphical User Interfaces 中華技術學院電子系 蔡樸生 副教授 林盈灝 副教授
Handle Graphics COMPONENT OBJECT HANDLE MODIFY PROPERTIES CALLBACK >> t = 0:0.1:4*pi; >> y = exp(-t/5).*sin(t) >> plot (t,y) >> propedit(gcf) gcf return the handle of current figure
Object (Computer Screen) Root Figure Page 504 Uicontrol Uimenu Axis Checkbox Pushbutton Edit Listbox Line Image Text Surface rectangle Patch
Get AND Set • The two function are used to obtain or change Handle Graphics object properties. >> t = 0:0.1:4*pi; >> get ( h,’color’) >> y = exp(-t/5).*sin(t); >> get ( h ) >> h = plot(t,y); >> set ( h,’linewidth’,3) >> set ( h,’Marker’,’o’) >> set ( h,’MarkerSize’,20);
UICONTROLCreate user interface control • Matlab supports 10 unicontrol style. • Format : width / Length • uicontrol ( ‘style’,’oooo’,’position’,[x,y,w,l]); • oooo : push / slide / radio / frame /check / edit • uicontrol (‘style’,’list’,’position’,[200 320 80 30], ‘string’,’1|2|3|4’); • uicontrol (‘style’,’popup’,’position’,[200 370 80 30], ‘string’,’one|two|three|four’);
Type of Uicontrol Popup Push Slide Frame Check Radio Edit List
Create Figure Window & Axes • figure : Create Figure Window. figure('position',[20 20 700 500]); 產生新的視窗,其左下角之座標為[20,20] 長度為700,寬度為500 • axes : Create axes in arbitrary positions. • axes ('position', RECT) • RECT = [left, bottom, width, height](page477) • axes('position',[0.1 0.2 0.8 0.75]); • axis([-20 20 -20 20]);
Example - GUI Design clear; figH=figure('position',[20 20 700 500]); axes('position',[0.1 0.2 0.8 0.75]); axis([-15 15 -15 15]); pos1=[60,20,100,30]; h1=uicontrol('style','push','string','Simulation','position',pos1); set(h1,'callback','simulation'); pos2=[335,23,80,24];
Example - GUI Design h2=uicontrol('style','popupmenu','tag','UI9','string','Skew|Gradient|Chain|','position',pos2); pos3=[175,20,50,30]; h3=uicontrol('style','push','string','Clear','position',pos3); set(h3,'callback','mr_parking'); pos4=[240,20,80,30]; h4=uicontrol('style','push','string','Response','position',pos4) set(h4,'callback','responsefig');
Homework (I) • Design a user window interface, the operate environment as following : S 型曲線 四尖擺線 螺旋流線 1
Homework (II) – PID套裝軟体之設計 • 套裝軟体首頁之設計 • 按 ‘進入’, 程式進入之PID套裝軟体畫面 • 可自由設計 P , I , D 三個參數, 並繪製響應圖 • 參考文獻 MATLAB程式設計與應用: CHAPTER 6 : 影像顯示與讀寫 Mastering -MATLAB 6 CHAPTER 28 : Images , Movies , and sound
PID 控制參數之調諧 • x1=0;x2=0;dt=0.01;r=1;step=2000;kcp=200; • tcp=0.44; • kp=kcp*0.6;Td=0.125*Tcp;Ti=0.5*Tcp; • kd=kp*Td;ki=(kp/Ti);pe=r-x1;ie=(r-x1)*dt; • Ziegler-Nichols Tuning : 響應速度加快, 但超越量過大為最大問題 • 自行驗證一個最佳化之調諧參數
Uicontrol – POPUP / LIST • pos1=[335,23,80,24]; • h1= uicontrol ( 'style', 'popup', 'string' , ‘one|two|three|four|','position',pos1); • set(h1,'callback',‘sub_1'); • switch get(h1,'value') • case 1 • statement (subroutine1) ; disp('one') • case 2 • statement (subroutine2) ; disp(‘two') • end
Uicontrol – EDIT • pos2=[Left, Bottom, Width, Height]; • h2=uicontrol('style','edit','string',int2str(initial_x),'position',pos2,'backgroundColor',[1 1 1]); • pos3=[Left, Bottom, Width, Height ]; • h3= uicontrol('style','push','string','Test','position',pos3); • set(h3,'callback',‘sub_3'); • sub_3 subroutine • x=(str2num(get(h2,'string')))
Uicontrol – CHECK/RADIO • pos4=[450,20,80,20]; • h4=uicontrol('style','check','string','Grid on','position',pos4,'value',0); • set(h4,'callback',‘sub_4'); sub_4: • switch get(h4,'value') • case 0 • grid off; • case 1 • grid on; • end