7-4 ?M 檔????形?件?性質存?

{bAzӬݹLܦhH GUI D MATLAB ε{FaH]pG٨SAлָո xpsoundBtravelBtrussBlorenz OC^`N²椶ЦpbOإ GUI ]pC]t@ GUI ]pkAhOϥ GUIDE oiҡAԨU@СC^

MATLAB uicontrol O UI (User Interface) 󪺥DnOAo UI ]tG

HUO@Ӳͫs]Push Button^²dҡG

Example 1: 07-⦡ϧλPGUI]p/uicontrol01.mh = uicontrol; % ͫs set(h, 'String', 'ЫڡI'); % bs[JruЫڡIv cmd = 'fprintf(''Hڤ@UI\n'');'; % wqsQ᪺O set(h, 'Callback', cmd); % ]wsO

bWzdҫAMATLAB |ͤ@ӪťյAW@ӫs]pUϡ^ACbI惡sAMATLAB OY|X{uHڤ@UIvrAп˦۸ոլݡI

bWҤAѩ UI OϧΪ󪺫ĤlA]YS{ϧεAMATLAB |sW@ϧεӮe UI C~AҦ UI 󪺡uOv]CallbacksAYU UI AMATLAB 檺O^HrөwqA]Ybʧ@SX{r]pWҪuHڤ@UIv^AhHӡu''v]Double Quote^ӮئrC]rꪺBzAiԨѲĤQurPrvC^ MATLAB 䴩 UI ie{pUG

Example 2: 07-⦡ϧλPGUI]p/uicontrol02.mclose all % Ҧϧε uicontrol('style', 'push', 'position', [200 20 80 30]); uicontrol('style', 'slide', 'position', [200 70 80 30]); uicontrol('style', 'radio', 'position', [200 120 80 30]); uicontrol('style', 'frame', 'position', [200 170 80 30]); uicontrol('style', 'check', 'position', [200 220 80 30]); uicontrol('style', 'edit', 'position', [200 270 80 30]); 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');

bWzҤlAstyle ᭱ұrYN UI OA position ᭱ұVqYN UI bϧεmAH [x, y, width, length] ҡAYN UI 󪺥UyЬ [x, y]A׬ widthA׬ length ]H Pixel ^C

HUХt~@ӸҤlAɮצW٬ ui01.mAzib MATLAB OUJuui01vAYio@ӹϧεά UI ApUϡG

Example 3: 07-⦡ϧλPGUI]p/ui01.m% ͷsϧεA䥪UyЬ[30, 30]A % ׬300A׬200]HPixel^ figure('position', [30 30 300 200]); % bϧεͤ@ӹ϶bA䥪UyЬ[0.1, 0.2], % ׬0.8A׬0.8]ϥμзǤƪAYϧΪU[0, 0]A % פΰ׳O1C^ axes('position', [0.1 0.2 0.8 0.8]); % WĤ@ӹϧΡATתŶpeaksơC pointNum = 20; [xx, yy, zz] = peaks(pointNum); surf(xx, yy, zz); colormap hsv axis tight % Ĥ@UIAΥHIuܡC h1 = uicontrol('style', 'checkbox', 'string', 'Grid on', ... 'position', [10, 10, 60, 20], 'value', 1); % ĤGUIAΥHwXbYblIƥءC h2 = uicontrol('style', 'edit', 'string', int2str(pointNum), ... 'position', [90, 10, 60, 20]); % ĤTUIAΥHwܦҥΨ쪺Lx}C h3 = uicontrol('style', 'popupmenu', ... 'string', 'hsv|hot|cool', ... 'position', [170, 10, 60, 20]); % Ĥ@UI󪺤OugridvC set(h1, 'callback', 'grid'); % ĤGUI󪺤Oucb2vC set(h2, 'callback', 'cb2'); % ĤTUI󪺤Oucb3vC set(h3, 'callback', 'cb3');

WzdҥiHͤ@ӹϧεA]tT UI G

ziHHNIΧܳo UI A[ϧΩMIܤơC

ŪAѳoӨҤlAڭ̦bl{X[FܦhѡAdҧ[²Cݪ`NOAd٩IsFt~Ӹ} cb2.m M cb3.mA䤤 cb2.m tdBzlIӼơAepUG

07-⦡ϧλPGUI]p/cb2.m% oĤGUI󪺼ƭȡC pointNum = round(str2num(get(h2, 'string'))); % YƦrӤjΤӤpAh]w10C if pointNum <= 1 | pointNum > 100, pointNum = 10; set(h2, 'string', int2str(pointNum)); end % ھکұoƦrAepeaksC [xx, yy, zz] = peaks(pointNum); surf(xx, yy, zz); axis tight; % ھڲĤ@UIAMwO_neuC if get(h1, 'value')==1, grid on; else grid off; end

cb3.m htdܦLx}AepUG

07-⦡ϧλPGUI]p/cb3.m% ھڲĤTUIӨMwϥΪLx}C switch get(h3, 'value') case 1 colormap(hsv); case 2 colormap(hot); case 3 colormap(cool); otherwise disp('Unknown option'); end

bWz² UI {]pdҤAڭ̥iHoıӯIG

  1. ݭnϥΥ|ɮסA޲zKC
  2. ϥΪܼƳb MATLAB 򥻤u@ŶAeyܼƪ۽Ĥл\C

ѨMWzD@²檺kAONҦ{X@Ө禡AåHPJrӫܨƩһݰ檺\A GUI {]pkb MATLAB U Demo {`QΨAS٬uSwitchyard ProgrammingvCHWҨӻAHuSwitchyard ProgrammingvӲͪ M ɮץiܦpUG

Example 4: 07-⦡ϧλPGUI]p/ui02.mfunction ui02(action) % ui02: Example of UI programming using "switchyard programming" % Roger Jang, 20040405 if nargin<1, action='initialize'; end switch(action) case 'initialize' % ϧεUI󪺪lơC % ͷsϧεA䥪UyЬ[30, 30]A % ׬300A׬200]HPixel^ figH = figure('position', [30 30 300 200]); % bϧεͤ@ӹ϶bA䥪UyЬ[0.1, 0.2], % ׬0.8A׬0.8]ϥμзǤƪAYϧΪU[0, 0]A % פΰ׳O1C^ axes('position', [0.1 0.2 0.8 0.8]); % WĤ@ӹϧΡATתŶpeaksơC pointNum = 20; [xx, yy, zz] = peaks(pointNum); surf(xx, yy, zz); colormap hsv axis tight % Ĥ@UIAΥHIuܡC h1 = uicontrol('style', 'checkbox', ... 'tag', 'ui4grid', ... 'string', 'Grid on', ... 'position', [10, 10, 60, 20], 'value', 1); % ĤGUIAΥHwXbYblIƥءC h2 = uicontrol('style', 'edit', ... 'tag', 'ui4pointNum', ... 'string', int2str(pointNum), ... 'position', [90, 10, 60, 20]); % ĤTUIAΥHwܦҥΨ쪺զLC h3 = uicontrol('style', 'popupmenu', ... 'tag', 'ui4colorMap', ... 'string', 'hsv|hot|cool', ... 'position', [170, 10, 60, 20]); % Ĥ@UI󪺤OugridvC set(h1, 'callback', 'grid'); % ĤGUI󪺤Ouui02('setPointNum')vC set(h2, 'callback', 'ui02(''setPointNum'')'); % ĤTUI󪺤Ouui02('setColorMap')vC set(h3, 'callback', 'ui02(''setColorMap'')'); case 'setPointNum' % ĤGUIcallbackC % XĤ@βĤGUI󪺴C h1 = findobj(0, 'tag', 'ui4grid'); h2 = findobj(0, 'tag', 'ui4pointNum'); % oĤGUI󪺼ƭȡC pointNum = round(str2num(get(h2, 'string'))); % YƦrӤjΤӤpAh]w10C if pointNum <= 1 | pointNum > 100, pointNum = 10; set(h2, 'string', int2str(pointNum)); end % ھکұoƦrAepeaksC [xx, yy, zz] = peaks(pointNum); surf(xx, yy, zz); axis tight; % ھڲĤ@UIAMwO_neuC if get(h1, 'value')==1, grid on; else grid off; end case 'setColorMap' % ĤTUIcallbackC % XĤTUI󪺴C h3 = findobj(0, 'tag', 'ui4colorMap'); % ھڲĤTUIӨMwϥΪLx}C switch get(h3, 'value') case 1 colormap(hsv); case 2 colormap(hot); case 3 colormap(cool); otherwise disp('Unknown option'); end otherwise error('Unknown action string!'); end

WҩҲͪ UI M\AM ui01.m @ˡAuΨ@ӳ@ɮסAbܦhAӥB|oܼƬ۽ĪDC

tAbWҤAڭ̬FnXT UI 󪺴A]SO]wḼӧOuTagvȡA]YnΨo UI Ai findobj OӪӧXL̪AD`KC


MATLAB{]pGJg