8-2 GUIDE �J���d�Ҥ@

­º¥ý¡A§Ú­Ì¥ý§ïÅÜ GUIDE ­±ª©ªº¤j¤p¡]¥i¸g¥Ñ©ì©ñ­±ª©¥k¤U¨¤ªº¶ÂÂI¨Ó¹F¦¨¡^¡A¨Ã¦b­±ª©¤W©ñ¸m¨â­Ó±±¨îª«¥ó¡A¤@­Ó¬O¡u©ÔÅQ¡v¡]Slider¡^¡A¥t¤@­Ó¬O¡u¥i½s¿è¤å¦rÄæ¦ì¡v¡]Edit Text¡^¡A¦p¤U¡G

±µµÛ¡A§Ú­Ì¥i¥H¨Ï¥Î·Æ¹«¥kÁä¨ÓÂI¿ï¥ô¤@­Ó UI ±±¨îª«¥ó¡A¨Ã¿ï¨ú¡uInspect Properties¡v¡A¥H§ïÅܨä©Ê½è¡C¥H¤W­±ªº©ÔÅQ¬°¨Ò¡A¥H·Æ¹«¥kÁäÂI¿ï«á¡A¿ï¨ú¡uInspect Properties¡v¡A§Y¥i¶}±Ò¡u©Ê½èÀ˵ø¾¹¡v¡]Property Inspector¡^¡A¨ä¥~Æ[¦p¤U¡G

¦b¦¹©Ê½èÀ˵ø¾¹¤¤¡A¥ªÃä¬Oª«¥óªº©Ê½è¡A¥kÃä«h¬O¦¹©Ê½è©Ò¹ïÀ³ªº­È¡A§Ú­Ì¥i¥HÂI¿ï¥kÃä¨Ó§ïÅܳo¨Ç­È¡C§Ú­Ì­º¥ý­n°µªº¨Æ¡A´N¬O³]©w¥Ø«e­±ªO¤Wªº¨â­Óª«¥óªº¥N¸¹¡A«áÄò¹ï¦¹ª«¥óªº³B²z¡A§Ú­Ì³£·|®Ú¾Ú¦¹¥N¸¹¨Ó¶i¦æ¡C¸g¥Ñ¡u©Ê½èÀ˵ø¾¹¡v¡A§Ú­Ì¥i¥H¶i¦æ¦p¤U¡G

§¹¦¨ª«¥ó¥N¸¹ªº³]©w«á¡A§Ú­Ì´N¥i¥H³]©wª«¥óªº¤ÏÀ³©R¥O¡C§Ú­Ì§Æ±æ³o¨Ç¤ÏÀ³©R¥O¯à°÷¨Ï³o­Ó GUI À³¥Îµ{¦¡¹F¨ì¤U¦C¥\¯à¡G

¦b GUIDE ªºÀô¹Ò¤U¡A¤@­Óª«¥óªº¤ÏÀ³©R¥O³£¬O¥Ñ¤@­Ó¯S©wªº¨ç¦¡¨Ó§¹¦¨¡A³o­Ó¨ç¦¡´NºÙ¬°¤ÏÀ³¨ç¦¡¡A¦Ó¨ç¦¡¦WºÙ´N¬O¡uª«¥ó¥N¸¹_Callback¡v¡C

­º¥ý¡A§Ú­Ì¥H·Æ¹«¥kÁäÂI¿ï©ÔÅQ¡A¨Ã¿ï¨ú¡uView Callbacks/Callback¡v¡A§Y¥i¶}±Ò MATLAB µ{¦¡½s¿è¾¹¡C¡]¦pªG§A©|¥¼¦sÀÉ¡AMATLAB ·|­n¨D§A¥ý¦sÀÉ¡A¤~¯àÄ~Äò¡C§A¥i¥H¸g¥Ñ GUIDE ¥Dµe­±±NÀÉ®×Àx¦s¦¨ myGui01.fig¡A¤§«á©Ò¦³¬ÛÃöµ{¦¡½X§Y·|³QÀx¦s¨ì myGui01.m¡C¡^¦¹µ{¦¡½s¿è¾¹·|Åã¥Ü¤ÏÀ³©R¥O¥²¶·¥[¤Jªº¦ì¸m¡A¨Ì¥»¨Ò¦Ó¨¥¡A©ÔÅQªº Tag ¬O mySlider¡A©Ò¥H¨ä¤ÏÀ³¨ç¦¡¬O mySlider_Callback()¡A©Ò¥[¶i¥hªº¨â¦C±Ô­z¦p¤U¡G

position = num2str(get(handles.mySlider, 'Value')); set(handles.myText, 'String', position);

¨ä¤¤²Ä¤@¦C±Ô­z§ì¥X©ÔÅQªº¦ì¸m¡A¨ÃÂন¼Æ­È¡A²Ä¤G¦C«h±N¦¹¼Æ­È³]©w¬°¤å¦rÄæ¦ìªºÅã¥Ü¤å¦r¡C¥[¤Jªº¦ì¸m¦p¤U©Ò¥Ü¡G

¨Ï¥Î¬Û¦Pªº¤è¦¡¡A§Ú­Ì¤]¥i¥H¥[¤J¤å¦rÄæ¦ìªº¤ÏÀ³©R¥O¡A¨ä¤ÏÀ³¨ç¦¡¬O myText_Callback()¡A©Ò¥[¶i¥hªº¨â¦C±Ô­z¦p¤U

value = str2double(get(handles.myText, 'String')); set(handles.mySlider, 'Value', value);

¨ä¤¤²Ä¤@¦C¬O§ì¥X¤å¦rÄæ¦ìªºÅã¥Ü¤å¦r¡AµM«áÂন¼Æ­È¡AµM«á¦b²Ä¤G¦C±N©ÔÅQªº¦ì¸m³]©w¦¨¦¹¼Æ­È¡C¥[¤Jªº¦ì¸m¦p¤U©Ò¥Ü¡G

¥[¤J³o¨Ç¤ÏÀ³©R¥O«á¡A§Y¥iÀx¦sÀɮרÃÃö³¬ MATLAB ½s¿è¾¹¡AµM«á«ö¤U GUIDE ­±ª©ªº¤u¨ã¦Cªº¤T¨¤§Î«ö¶s¡A§Y¥i¶}±Ò§Ú­Ì©Ò³]­pªº GUI ¤¶­±¦p¤U¡G

§A¥i¥Hª½±µ²¾°Ê©ÔÅQ¡A¨ä¦ì¸m´N·|Åã¥Ü¦b¤å¦rÄæ¦ì¤º¡F§A¤]¥i¥H­×§ï¤å¦rÄæ¦ìªº­È¡A¨Ó«ü©w©ÔÅQªº¦ì¸m¡C

¦pªG§A¤w¸g§¹¦¨¾ãÅé³]­p¬yµ{¡A¦¹®É¥i¥HÃö³¬ GUIDE ¥Dµe­±¡C¤§«á¥u»Ý¦b MATLAB ¿é¤J myGui01¡A§Y¥i¶}±Ò©Ò³]­pªº GUI µ{¦¡µe­±¡C­YÁٻݭn¶i¦æ GUI µ{¦¡ªº­×§ï¡A¥u»Ý¦b MATLAB ¿é¤J guide myGuide01¡A§Y¥i¶}±Ò GUIDE ¥Dµe­±¨ÃÄ~Äò¶i¦æ GUI µ{¦¡³]­p¡A¨Ò¦p¥[¤J·sªº±±¨îª«¥ó¨Ã©w¸q¬ÛÃö¤ÏÀ³©R¥Oµ¥¡C

¤W­z½d¨Ò¤w¸g¦¬¿ý¦b¥»®Ñ½d¨Ò¥Ø¿ý¤¤ªº gui01.m ©M gui01.fig¡C

±q³o­Ó½d¨Ò¤¤§Ú­Ì¥i¥Hª¾¹D¡A¦b³]­p¤ÏÀ³©R¥O®É¡A³Ì­«­nªº¨Æ¡A´N¬O­n¯àÅý¤£¦Pªº UI ±±¨îª«¥ó³£¯à¦s¨ú¨ä¥Lª«¥ó¥H¤Î¬ÛÃö¸ê®Æ¡A¦]¬°¨C¤@­Ó UI ±±¨îª«¥óªº¤ÏÀ³©R¥O³£¬O¥H¨ç¦¡ªº«¬¦¡¨Ó¶i¦æ¡A¦]¦¹ GUIDE ¦b¨C¤@­Ó¤ÏÀ³¨ç¦¡¤º´£¨Ñ¤F¤@­Óµ²ºcÅÜ¼Æ handles¡A¥H«K´£¨Ñ¸ê®Æªº¦@³q¡A¥i¹F¨ì¤U¦C¨â¶µ¥\¯à¡G

  1. ¥i¥H¸g¥Ñ handles ¨Ó¦s©ñ©Î¨ú¥Î¦@³qªº¸ê®Æ¡C
  2. ¥i¥H¸g¥Ñ handles ¨Ó¨ú±o¨C¤@­Ó UI ±±¨îª«¥óªº©Ê½è¡C

¨Ò¦p¡A­Y­n¦b¬Y¤@­Ó±±¨îª«¥óªº¤ÏÀ³¨ç¦¡¤º¦s©ñÅÜ¼Æ A¡A¥i¥H¥[¤J¤U¦C±Ô­z¡G

handles.myData = A; % ±NÅÜ¼Æ A ¦s©ñ¦b handles ªº myData Äæ¦ì guidata(hObject, handles) % ±N·sªº handles ¦s¦^¾ã­Ó GUI ¤¶­±

¦pªG­n¦b¥t¤@­Ó±±¨îª«¥óªº¤ÏÀ³¨ç¦¡¸Ì­±¨Ï¥ÎÅÜ¼Æ A¡A¥u­n¥[¤J¤U¦C±Ô­z§Y¥i¡G

A = handles.myData;

¥t¥~¡Ahandles ¥»¨­¤]¥]§t¤F¦P¤@­Ó GUI ¤¶­±¤Uªº©Ò¦³±±¨îª«¥ó¡A¥H¤W¤@¸`ªº½d¨Ò¨Ó»¡¡A§Ú­Ì©w¸q¤F¨â­Ó±±¨îª«¥óªº Tag¡A¦]¦¹§A¥i¥H¦b¥ô¤@­Ó¤ÏÀ³¨ç¦¡¤º¨ú¥Î¨C¤@­Ó±±¨îª«¥ó¡A¦p¤U¡G

handles.mySlider¡G©ÔÅQª«¥ó handles.myText¡G¤å¦rÄæ¦ìª«¥ó

¦pªG¾ã­Ó GUI ªº¦WºÙ¬O myGUI¡A¨º»ò handles.myGUI ´N¬O«ü¨ì¾ã­Ó GUI ªº¹Ï§Î¡A¦]¦¹­Y­nÃö³¬¦¹µøµ¡¡A¤]¥i¥H¨Ï¥Î¤U¦C±Ô­z¡G

delete(handles.myGUI)
MATLABµ{¦¡³]­p¡G¤Jªù½g