欢迎来到天天文库
浏览记录
ID:44276519
大小:379.00 KB
页数:15页
时间:2019-10-20
《《MATLAB及其工程应用》第5讲》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、MATLAB&ItsApplicationsInEngineering李清都副教授liqd@cqupt.edu.cnLect.5:BranchStatementContentsCovered:Top-downdesignTechniquesrelational&logicaloperatorsBranchstatements:‘if-elseif-else-end’,‘switch-case-otherwise-end’Objectives:UnderstandtheconceptsofTop-downdesignflowfirm
2、lygrasptheusageofrelational&logicaloperatorsFirmlygrasptheusageof‘if-elseif-else-end’,‘switchcaseotherwiseend’StrengthentheskillonwritinganddebuggingM-fileTop-downDesignFlowMorecomplicatedcontrolstatementsTosolvecomplicatedproblems,youhavetowritemorecomplicatedprograms
3、.branching&loopingRelationaloperators==~=><>=<=1)nottoconfusethe‘==‘with‘=‘2)relationaloperatorshaslowerhierarchythanarithmeticoperationsGoodProgrammingpracticeAlwaysuseparenthesestoindicatetheorder7+3<2+11(7+3)<(2+11)Whatistheresult?a=0;b=sin(pi);c=(a==b);Logicalopera
4、tors&
5、xor~HierarchyofoperationsArithmeticoperatorsRelationaloperators(fromlefttoright)~&
6、!Logicalfunctionsisequal()isempty()isinf()isnan()isnumeric()Theifconstructifexpression_1statement_1elseifexpression_2statement_2elsestatement_3endExampleusingifconstructscore=input
7、(‘pleaseinputyourscore:‘);ifscore>=90grade=‘Excellent’;elseifscore>=70grade=‘Good’;elseifscore>=60;grade=‘Passed’;elsegrade=‘Failed’;enddisp(grade);Theswitchconstructswitch(swtich_expression)casecase_expr_1statement_1casecase_expr_2statement_2otherwisestatement_3endExa
8、mpleusingswitchconstructpassword=input(‘pleaseinputyourpassword:‘);switchpasswordcase‘matlab’privilege=‘WRITE_ONLY’;case‘pld’privilege=‘READ_ONLY’;otherwiseprivilege=‘FORBIDDEN’;endAssignment:Excises3.2,3.3,3.4,3.5
此文档下载收益归作者所有