关于Matlab中的GUA 的Brief Introduction to handles.docx
《关于Matlab中的GUA 的Brief Introduction to handles.docx》由会员分享,可在线阅读,更多相关《关于Matlab中的GUA 的Brief Introduction to handles.docx(20页珍藏版)》请在冰豆网上搜索。
关于Matlab中的GUA的BriefIntroductiontohandles
MATLABGUITutorial-ABriefIntroductiontohandles
13Nov2007QuanQuach58comments12,689views
Introduction
Inthistutorial,wewilldiscusswhathandlesareandhowtousethegetandsetcommands.WhendealingwithaMatlabGUI,youhaveprobablynoticedthevariablehandlesbeingusedintheaccompanying.mfile.Thehandlesstructurecontainsalltheinformationforeachobjectinthe.figfileoftheGUI.Butitcanalsostoreotherinformation.Let’sexplorealittlebitmoreabouthandles.
ThistutorialiswrittenforthosewithsomeexperiencecreatingaMatlabGUI.Ifyou’renewtocreatingGUIsinMatlab,youshouldvisitthistutorialfirst.BasicknowledgeofMatlabisrecommended.Matlabversion2007aisusedinwritingthistutorial.Bothearlierversionsandnewversionsshouldbecompatibleaswell(aslongasitisan’ttoooutdated).
Handles,get,andset
1.First,downloadthesampleGUIhere.Unzipthefilesandplacethemwhereveryouplease.
2.Now,typeguideatthecommandprompt.
3.ChoosetoopenthesampleGUIbyclickingon“OpenExistingGUI”.Clickon“Browse”tolocatewhereyousavedtheGUIfiles.
4.HereiswhattheGUIshouldlooklikewhenyouopenit:
5.Thehandlesstructurecontainsalltheinformationforthepushbutton,radiobutton,statictext,thefigureitself,aswellasoutput.Sohowexactlydoweviewandaccessthisinformation?
Therearetwowaystodothis.Clickonthe
iconontheGUIfiguretobringuptheaccompanying.mfile.Youcaninsertinabreakpointbyleftclickingontheleftsideofthe.mfileasshown.
Oryoucantypeinkeyboardintothe.mfile,asshownbelow.
Bothmethodsresultinthesamething.ThiscausestheGUItogointocommandlinemode,allowingyoutoexamineandchangethefunction’slocalworkspace.(Incidentally,thisisagreatwaytodebugyourcode!
)
6.Let’susethekeyboardmethodforthistutorial.
Typekeyboardrightbelowpushbutton1_Callback,asshowninthefigureabove.
7.Now,saveandruntheGUI.Pressthepushbutton.
8.Thecommandwindowshouldpopupandyoushouldseethefollowingatthecommandwindow.Noticethenormalcommandlinehasbeenreplacedwith“K>>”.Thisjustmeansthatyou’reinkeyboardmode.
Handles,get,andset(cont)
1.Now,let’stakealookatthevariableswithinthefunction’sworkspace.Typewhosatthecommandprompt.Thiscommandtellsyouwhatvariablesareinthelocalworkspace.Nothingtoointeresting.
2.Now,let’stakealookatthehandles.Typehandlesatthecommandprompt.Thiscommandgivesyoumoredetailsonthehandlesstructures.You’llnoticethateachobjectontheGUIfigureisaccountedfor.(figure1isthebackgroundimagethatyourcomponentsareplacedon)
3.Letssayyouwantedmoredetailsonthepropertiesofradiobutton1.Youcantypeget(handles.radiobutton1)atthecommandprompttogetalistofallthepropertiesofthisobject.Thiscommandwilldisplayallthepropertiesofthatcomponent,similartowhatyouwouldseeinthePropertyInspectorwhenyoudoubleclickonthiscomponentintheGUIDEfigure.
4.Let’ssayyouonlywanteddetailsontheStringpropertyforradiobutton1;youcantypeget(handles.radiobutton1,'String')atthecommandprompt.Additionally,youcanstorethisvalueintoavariableforlateruse.ThegetcommandisprobablyusedmostoftenwithEditTextcomponentstoextractuserinputs.
5.LetssayyouwantedtochangetheStringpropertyonradiobutton1.Youcandothisbyusingset(handles.radiobutton1,'String','helloworld')atthecommandprompt.
NoticethatanychangesyoumakeusingthesetcommandareinstantlyreflectedontheGUIprogram(nottheGUIDEfigure,buttheactualGUIthatisrunning).
6.Tryinsertingthesecommandsintothecommandline:
set(handles.radiobutton1,'String','Thebuttonischanged!
')
set(handles.radiobutton1,'BackGroundColor',[1,.3,1])
TheGUIthatisrunningshouldnowlooklikethis:
7.Afteryou’redoneplayingaround,typereturnatthecommandprompttoexitkeyboardmode.Next,youshoulderasethekeyboardcommandthatyouplacedinthe.mfileandsaveit.Otherwise,theGUIwillkeepgoingintokeyboardmodewhenyoupushthatbutton.
58Responsesto“MATLABGUITutorial-ABriefIntroductiontohandles”
1.on14Dec2007at9:
19am1Tongtong
Thisquickshorttutorialisaclear,simplebutalsoveryinformativeone.Thanks.Ithelpsmetounderstandhandlesbetter.
2.on15Dec2007at6:
13pm2luis
Iagreewithtongtong,anotherusefulhandout.goodwork.
3.on07Jan2008at12:
13am3hlowyqdmqko
sbftjwrlkcebtxewowceffzjyambaghxvbtjbxfrkse
4.on18Feb2008at5:
32am4DaveBarr
Thanksforthepointertothistutorial-Itanswersmyproblemonhandlesexactlyandwhatasmoothwayoftesting/debuggingcode.
YourtutorialsarefareasiertounderstandthantheofficialMathlabones.
Regards
Dave
5.on19Feb2008at11:
43am5serotonin
youaredoingexcellentwork,thanksandpleasekeepon
6.on21Feb2008at6:
45am6Sikander
Mr.Q.Quanch
youdidExcelentjobtointroducehandles,briefly.Ihavefewquestions,
Q1:
isitpossibletouseh.orH.insteadofcompletehandleword?
?
?
?
?
?
?
Q2:
whatissuitablebuttontouseanimageaxisoractiveXcontrol?
?
?
morequestionswillbeforword.ifreceivedtheanswerofthesetwo
withbestregards
SikanderHayat
7.on21Feb2008at5:
03pm7QuanQuach
Sikander,
bydefault,youhavetousetheword“handles”toaccessthestructure.
Personally,Iprefertotheusetheimageaxistoplaceapicturebecauseitismorestableacrossthedifferentversionsofmatlab.
Quan
8.on04Mar2008at4:
48am8Ramya
hi,
thetutorialsarereallyhelpful.CanuplzsuggestsomesiteswhichhasprogrammingformedicalX-rayimages?
9.on12Mar2008at3:
15am9Saeed
Thaswasquickandmuchhelpfulthanks
10.on24Apr2008at1:
36am10Ali
Thanksforthetutorial,useful…..
11.on05May2008at4:
52am11mitra
hi
tnxfortehusefullinformation
butihadanotherquestion,isitpossibletocalloneofthesubfunctionsinguifromanotherfunction?
ihaveaguiandinthatiamcallinganotherfileandiwanttoplottheresultsinthissecondfunctionbutbecauseofsomeproblemsicannotsendthehandletothisfile,soithoughtmaybeicanhaveafunctioninguiandcalliteachtime.isthereanyway?
tnx
12.on06Jul2008at6:
57am12matteo
Thankyouforthisexcellenttutorial,IfounditmuchmoreinformativethantheMATLABdocumentation.
Thanks,
Matteo
13.on17Aug2008at12:
43am13Titoo
excellentjob,thankyoualot.
14.on20Aug2008at8:
29pm14Nr
verydescriptiveandinformativetutorial.Also,itiseasytolearnbecauseofsimpledescription.Thankyouverymuchforhandlesdescription.
15.on13Sep2008at8:
55am15louis
pleasehelpmeinmyprojectitisadtmfdoorlocksystem,youmustfirstcreateapasswordandthenyoumustlogininthekeypadcreatedusingdtmfandenteryourpasswordcorrectly
pleasehelpmeineedtopassthisonorbeforetuesdaypleaseguystothosewhoaregiftedwithmatlabskills….thankspleaseemailmeatlnvp_17@ifyoullhelpilreferyoutomyschoolmatesGodbless
16.on16Sep2008at1:
05am16Fikri
HiQuan,
I’mbuildingaGUI,sofarsogooduntilItriedtomakeitobjectoriented.SaythatmyGUIisinafunctioncalledgui.m,andtheessentialfunctionthatisgoingtobeusedbygui.marebothdct.mandtmt.m,hereliestheproblem,bothdct.mandtmt.mproduceshistograms,whichusespanelsinsidegui.mforgeneratingthehistograms.HowdoIdealwiththecoding,sinceitwilluseahandleforthepanelinsidethegui.m
Whatwouldyousuggestmeinthissituation.
Regards,
Fikri
17.on23Nov2008at7:
35pm17rajesh
Hey
Thankyousomuchforcreatingthispiece.Ihadbeentryingtounderstandhandlesforthewholedayandthese5minutesarethemostusefulones.
18.on13Mar2009at8:
38am18abdo
Hello………
pleaseineedhelp,ihaveprojectabout”freedomforrobotics”….”armmanipulatorforrobotics”…pleasehelpme…ineeduse”GUIMATLAB”
19.on18Mar2009at12:
49am19scf
I’musingyourexamplecode,butwhenItypein“whos”thehandlesstructisempty!
pleaseadvise…
20.on20Mar2009at3:
41am20Francesco
Higuys,
i’musingmatlabr2008btodevelopagui.Ihaveaproblemwithhandlesproperty:
wheniusegetcommandtoextractthestringinanedittext
radIds1=str2double(get(handles.rad_Ids1_edit,'String'));
Matlabnotices
?
?
?
Errorusing==>get
Thereisno‘String’propertyinthe‘root’class.
Ifiuse
get(handles.rad_Ids1_edit)
ihaveonly
CallbackObject=[2090]
CommandWindowSize=[6822]
CurrentFigure=[2050]
Diary=off
DiaryFile=diary
Echo=off
FixedWidthFontName=CourierNew
Format=short
FormatSpacing=loose
Language=it_it.windows-1252
MonitorPositions=[(2by4)doublearray]
More=off
PointerLocation=[494397]
PointerWindow=[0]
RecursionLimit=[500]
ScreenDepth=[32]
ScreenPixelsPerInch=[96]
ScreenSize=[111024600]
ShowHiddenHandles=off
Units=pixels
BeingDeleted=off
ButtonDownFcn=
Children=[2050]
Clipping=on
CreateFcn=
DeleteFcn=
BusyAction=queue
HandleVisibility=on
HitTest=on
Interruptible=on
Parent=[]
Selected=off
SelectionHighlight=on
Tag=
Type=root
UIContextMenu=[]
UserData=[]
Visible=on
stringpropertythereisn’t.Why?
Francesco
21.on20Mar2009at9:
44am21ZaneMontgomery
HiFransesco,
Itlookslikesomethingiswrongwithyouredittextbox.Yourhandlesmakeitseemlikeyou’veaccessedthematlabrootwhichyoudon’twanttochange(I’mguessing).
“Therooti