Matlab程序调试相关函数.docx
- 文档编号:4115200
- 上传时间:2022-11-28
- 格式:DOCX
- 页数:6
- 大小:17.08KB
Matlab程序调试相关函数.docx
《Matlab程序调试相关函数.docx》由会员分享,可在线阅读,更多相关《Matlab程序调试相关函数.docx(6页珍藏版)》请在冰豆网上搜索。
Matlab程序调试相关函数
kyboard:
KEYBOARDInvokekeyboardfromM-file.
KEYBOARD,whenplacedinanM-file,stopsexecutionofthefile
andgivescontroltotheuser'skeyboard.Thespecialstatusis
indicatedbyaKappearingbeforetheprompt.Variablesmaybe
examinedorchanged-allMATLABcommandsarevalid.Thekeyboard
modeisterminatedbyexecutingthecommandRETURN(i.e.typing
thesixlettersR-E-T-U-R-Nandpressingthereturnkey.Control
returnstotheinvokingM-file.
DBQUITcanalsobeusedtogetoutofkeyboardmodebutinthiscase
theinvokingM-fileisterminated.
ThekeyboardmodeisusefulfordebuggingyourM-files.
Seealsodbquit,dbstop,return,input.
ReferencepageinHelpbrowserdockeyboard
dbquit:
Quitdebugmode.
TheDBQUITcommandimmediatelyterminatesdebugmodeandreturns
controltothebaseworkspaceprompt.TheM-filebeingprocessed
isNOTcompletedandnoresultsarereturned.
Seealsodbstop,dbcont,dbstep,dbclear,dbtype,dbstack,dbup,
dbdown,anddbstatus.
ReferencepageinHelpbrowserdocdbquit
dbstop:
Setbreakpoint.
TheDBSTOPcommandisusedtotemporarilystoptheexecutionofanM-file
andgivetheuseranopportunitytoexaminethelocalworkspace.Thereare
severalformstothiscommand.Theyare:
(1DBSTOPinMFILEatLINENO
(2DBSTOPinMFILEatLINENO@
(3DBSTOPinMFILEatLINENO@N
(4DBSTOPinMFILEatSUBFUN
(5DBSTOPinMFILE
(6DBSTOPinMFILEatLINENOifEXPRESSION
(7DBSTOPinMFILEatLINENO@ifEXPRESSION
(8DBSTOPinMFILEatLINENO@NifEXPRESSION
(9DBSTOPinMFILEatSUBFUNifEXPRESSION
(10DBSTOPinMFILEifEXPRESSION
(11DBSTOPiferror
(12DBSTOPifcaughterror
(13DBSTOPifwarning
(14DBSTOPifnaninforDBSTOPifinfnan
(15DBSTOPiferrorIDENTIFIER
(16DBSTOPifcaughterrorIDENTIFIER
(17DBSTOPifwarningIDENTIFIER
MFILEmustbethenameofanM-fileoraMATLABPATH-relativepartial
pathname(seePARTIALPATH.LINENOisalinenumberwithinMFILE,Nisan
integerspecifyingtheNthanonymousfunctionontheline,andSUBFUN
isthenameofasubfunctionwithinMFILE.EXPRESSIONisastringcontaining
aevaluatableconditionalexpression.IDENTIFIERisaMATLABMessage
Identifier(seehelpforERRORforadescriptionofmessage
identifiers.TheATandINkeywordsareoptional.
Theformsbehaveasfollows:
(1StopsatthespecifiedlinenumberinMFILE.
(2Stopsjustafteranycalltothefirstanonymousfunction
inthespecifiedlinenumberinMFILE.
(3As(2,butjustafteranycalltotheNthanonymousfunction.
(4StopsatthespecifiedsubfunctionofMFILE.
(5StopsatthefirstexecutablelineinMFILE.
(6-10As(1-(5,exceptonlystopsifEXPRESSIONevaluatesto
true.EXPRESSIONisevaluated(asifbyEVALinMFILE'sworkspace
whenthebreakpointisencountered,andmustevaluatetoascalar
logicalvalue(trueorfalse.
(11CausesastopinanyM-filefunctioncausingarun-timeerrorthat
wouldnotbedetectedwithinaTRY...CATCHblock.
YoucannotresumeM-fileexecutionafteranuncaughtrun-timeerror.
(12CausesastopinanyM-filefunctioncausingarun-timeerrorthat
wouldbedetectedwithinaTRY...CATCHblock.YoucanresumeM-file
executionafteracaughtrun-timeerror.
(13CausesastopinanyM-filefunctioncausingarun-timewarning.
(14CausesastopinanyM-filefunctionwhereaninfinitevalue(Inf
orNot-a-Number(NaNisdetected.
(15-17As(11-(13,exceptthatMATLABonlystopsonanerrororwarning
whosemessageidentifierisIDENTIFIER.(IfIDENTIFIERisthespecial
string'all',thentheseusesbehaveexactlylike(11-(13.
WhenMATLABreachesabreakpoint,itentersdebugmode.Thepromptchanges
toaK>>and,dependingonthe"OpenM-FileswhenDebugging"settinginthe
Debugmenu,thedebuggerwindowmaybecomeactive.AnyMATLABcommandis
allowedattheprompt.ToresumeM-fileexecution,useDBCONTorDBSTEP.To
exitfromthedebugger,useDBQUIT.
dbclear:
Removebreakpoint.
TheDBCLEARcommandremovesthebreakpointsetbyacorrespondingDBSTOP
command.Thereareseveralformstothiscommand.Theyare:
(1DBCLEARinMFILEatLINENO
(2DBCLEARinMFILEatLINENO@
(3DBCLEARinMFILEatLINENO@N
(4DBCLEARinMFILEatSUBFUN
(5DBCLEARinMFILE
(6DBCLEARifERROR
(7DBCLEARifCAUGHTERROR
(8DBCLEARifWARNING
(9DBCLEARifNANINForDBCLEARifINFNAN
(10DBCLEARifERRORIDENTIFIER
(11DBCLEARifCAUGHTERRORIDENTIFIER
(12DBCLEARifWARNINGIDENTIFIER
(13DBCLEARALL
MFILEmustbethenameofanM-fileoraMATLABPATH-relativepartial
pathname(seePARTIALPATH.LINENOisalinenumberwithinMFILE,andSUBFUN
isthenameofasubfunctionwithinMFILE.IDENTIFIERisaMATLABMessage
Identifier(seehelpforERRORforadescriptionofmessage
identifiers.TheATandINkeywordsareoptional.
Theseveralformsbehaveasfollows:
(1RemovesthebreakpointatlineLINENOinMFILE.
(2RemovesthebreakpointinthefirstanonymousfunctionatlineLINENO
inMFILE.
(3RemovesthebreakpointintheNthanonymousfunctionatlineLINENO
inMFILE.(Usethiswhenthereismorethanoneanonymousfunction
onthesameline.
(4RemovesallbreakpointsinthespecifiedsubfunctionofMFILE.
(5RemovesallbreakpointsinMFILE.
(6ClearstheDBSTOPIFERRORstatementandanyDBSTOPIFERROR
IDENTIFIERstatements,ifset.
(7ClearstheDBSTOPIFCAUGHTERRORstatement,andanyDBSTOPIFCAUGHT
ERRORIDENTIFIERstatements,ifset.
(8ClearstheDBSTOPIFWARNINGstatement,andanyDBSTOPIFWARNING
IDENTIFIERstatements,ifset.
(9ClearstheDBSTOPoninfinitiesandNaNs,ifset.
(10ClearstheDBSTOPIFERRORIDENTIFIERstatementforthespecified
IDENTIFIER.Itisanerrortoclearthissettingonaspecific
identifierifDBSTOPIFERRORorDBSTOPIFERRORALLisset.
(11ClearstheDBSTOPIFCAUGHTERRORIDENTIFIERstatementforthespecified
IDENTIFIER.Itisanerrortoclearthissettingonaspecific
identifierifDBSTOPifcaughterrororDBSTOPifcaughtERRORall
isset.
(12ClearstheDBSTOPIFWARNINGIDENTIFIERstatementforthespecified
IDENTIFIER.Itisanerrortoclearthissettingonaspecific
identifierifDBSTOPIFWARNINGorDBSTOPIFWARNINGALLisset.
(13RemovesallbreakpointsinallM-files,aswellasthosementionedin
(6-(9above.
Seealsodbstep,dbstop,dbcont,dbtype,dbstack,dbup,dbdown,dbstatus,dbquit,error,partialpath,try,warning.
ReferencepageinHelpbrowserdocdbclear
dbcont:
Continueexecution.
TheDBCONTcommandresumesexecutionofanM-filefollowingastopin
executioncausedbyeitheraDBSTOPorDBSTEPcommand.Executionwill
continueuntileitheranotherbreakpointisencountered,anerror
occurs,orMATLABreturnstothebaseworkspaceprompt.
Seealsodbquit,dbstep,dbstop,dbclear,dbtype,dbstack,dbup,dbdown,dbstatus.
ReferencepageinHelpbrowser
docdbcont
dbstatus:
Listallbreakpoints.
DBSTATUS,byitself,displaysalistofallthebreakpointsthedebugger
knowsaboutincludingERROR,CAUGHTERROR,WARNING,andNANINF.
DBSTATUSMFILEdisplaysthebreakpointssetforthespecifiedM-file.MFILE
mustbethenameofanm-filefunctionoraMATLABPATHrelativepartial
pathname(seePARTIALPATH.
DBSTATUS('-completenames'outputsthe"completename"ofeachfunction.
Acompletenameincludestheabsolutefilenameandtheentiresequenceof
functionsthatnestthefunctioninwhichabreakpointisset.
S=DBSTATUS(...returnsthebreakpointinformationinanM-by-1
structurewiththefields:
name--functionname.
file--fullnameofthefilecontainingbreakpoint(s.
line--vectorofbreakpointlinenumbers.
anonymous--integervector,eachelementofwhichcorrespondstoanelementofthe'line'field.Eachpositiveelementrepresentsabreakpointinthebodyofananonymousfunctiononthatline.Forexample,abreakpointinthebodyofthesecondanonymousfunctiononthelineresultsinthevalue2inthisvector.Ifanelementis0,thebreakpointisatthebeginningoftheline,i.e.,notinananonymousfunction.expression--cellvectorofbreakpointconditionalexpressionstringscorrespondingtolinesinthe'line'field.cond--conditionstring('error','caughterror','warning',or'naninf'.identifier--whencondisoneof'error','caughterror',or'warning',acellvectorofMATLABMessageIdentifierstringsforwhichtheparticularcondstateisset.Seealsodbstep,dbstop,dbcont,dbclear,dbtype,dbstack,dbup,dbdown,dbquit,error,partialpath,warning.ReferencepageinHelpbrowserdocdbstatusdbstack:
Displayfunctioncallstack.TheDBSTACKcommanddisplaystheM-filefunctionnameandlinenumberwherethebreakpointoccurred,thenameandlinenumberoftheM-filecaller,thecaller'scaller,etc.,untilthetop-mostM-filefunctionisreached.DBSTACK(NomitsfromthedisplaythefirstNframes.Thisisusefulwhenissuingadbstackfromwithin,say,anerrorhandler.DBSTACK('-completenames'outputsthe"completename"ofeachfunctioninthestack,whichmeanstheabsolutefilenameandtheentiresequenceoffunctionsthatnestthefunctioninthestackframe.Eithernone,one,orbothoftheNand'-completenames'mayappear.Ifbothappear,theorderisirrelevant.[ST,I]=DBSTACKreturnsthestacktraceinformationinanM-by-16
structureSTwiththefields:
file--thefileinwhichthefunctionappears;thisfieldwillbetheemptystringifthereisnofile.name--functionnamewithinthefileline--functionlinenumberThecurrentworkspaceindexisreturnedinI.IfyousteppasttheendofanM-file,thenDBSTACKreturnsanegativelinenumbervaluetoidentifythatspecialcase.Forexample,ifthelastlinetobeexecutedisline15,thentheDBSTACKlinenumberis15beforeyouexecutethatlineand-15afterwards.Seealso
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Matlab 程序 调试 相关 函数