版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Introduction to MATLABCheng-Hsiung ChiangDepartment of Computer ScienceHsuan Chuang University1.OutlineThe history of MATLABThe toolboxes of MATLABHow to use MATLAB software?Programming using MATLABBasic commandsWrite a function of MATLABArrays and matrixesOperations of arrays and matrixesMatlab fun
2、ctionsControl proceduresInput and outputPlottingExamples of MATLAB programs2The History of MATLABMATLAB ( Matrix Laboratory) is developed by The MathWorks, Inc., 1984.MATLAB最早的發展理念是提供一套非常完善的矩陣運算指令,但隨著數值運算需求的演變,matlab已成為系統模擬,數位訊號處理,科學目視的標準語言3MATLAB is the leading computational software forProduct des
3、ign and developmentResearch in industry and academiaTechnical education Over 400,000 MATLAB users worldwideUsed in over 100 countries4How powerful the MATLAB can be?“For the purposes of an engineer or scientist, MATLAB has the most features and is the best developed program in its class. -IEEE Spect
4、rum, Software Review, February 1997“I have been amazed at how MATLAB can boost ones productivity. Anything from simple analysis to complex modeling and simulation can be done in a fraction of the time it would take to write your own code.Gregory E. Chamitoff, Ph.D.NASA, Johnson Space Center5The Tool
5、boxes of MATLABCommunications ToolboxControl System ToolboxData Acquisition ToolboxDatabase ToolboxDatafeed ToolboxFilter Design ToolboxFinancial Derivatives ToolboxFinancial Derivatives ToolboxFinancial ToolboxFuzzy Logic ToolboxGARCH ToolboxImage Processing ToolboxInstrument Control ToolboxModel P
6、redictive Control ToolboxMapping ToolboxMu Analysis And Synthesis ToolboxNeural Network ToolboxOptimization ToolboxPartial Differential Equations (PDE) ToolboxRobust Control ToolboxSignal Processing ToolboxSpline ToolboxStatistics Toolbox Symbolic Math ToolboxSystem Identification ToolboxWavelet Too
7、lbox6How to use MATLAB?Install MATLABExecute MATLABThe MATLAB windowsDemos of MATLAB7Programming Using MATLABFile types of MATLAB.m file.fig files.mat filesBasic Commands in command windowsave load help whoclearclcexit/quit8Mathematical OperationsDeclaring a variableA = 5;% the “; is for not display
8、B = 6;MATLAB Math & Assignment OperatorsPoweror.abor a.bMultiplication* or.*a*bora.*bDivision/or./a/bora./b oror.baorb.aNOTE: 56/8 856Addition+ a + bSubtraction- a - b9Write a Function of MATLABHow to edit a function for MATLAB?An example of a MATLAB functionfunction total = sum(n) % This program is
9、 to calculate the summationsum = 0; for i = 1 : 10,sum = sum + I;end;% end of for loopend;% end of functionHow to call a function?10Arrays and MatrixesArray: ex. 1x6 arrayA = 1 2 3 4 5 6;orA = 1, 2, 3, 4, 5, 6;Matrix: ex. 2x3 matrixB = 1 2 3; 4 5 6; 7 8 9; orB = 1 2 3 4 5 6 7 8 9;A(1) = ? A (6) = ?
10、B(1,2) = ? B (1,:) = ? B(:,1) = ?Examples:11Operations of Arrays and MatrixesThe mathematical operations of array and matrix12Matlab FunctionsThe MATLAB functions13Flow control - selectionThe if-elseif-else constructionif elseif else endif height170 disp(tall)elseif height150 disp(small)else disp(av
11、erage)end14Logical expressionsRelational operators (compare arrays of same sizes)= =(equal to)= (not equal) (less than)(greater than)= (greater than or equal to)Logical operators (combinations of relational operators)&(and)|(or)(not)Logical functionsxorisemptyanyallif (x=0) & (x=10) disp(x is in ran
12、ge 0,10)else disp(x is out of range)end15Flow control - repetitionRepeats a code segment a fixed number of timesfor index= endThe are executed repeatedly.At each iteration, the variable index is assigneda new value from .for k=1:12 kfac=prod(1:k); disp(num2str(k), ,num2str(kfac)end16Example selectio
13、n and repetitionfunction y=fact(n)% FACT Display factorials of integers 1.nif nargin 1 error(No input argument assigned)elseif n eps error(Input must be an integer)endfor k=1:n kfac=prod(1:k); disp(num2str(k), ,num2str(kfac) y(k)=kfac;end;17Repetition: Animation demoThe function movie replays a sequ
14、ence of captured framesConstruct a movie of a 360 tour around the Matlab logo% logomovie make movie of 360 degree logo tour logo;no_frames=40;dtheta=360/no_frames;for frame = 1:no_frames, camorbit(dtheta,0) M(frame) = getframe(gcf);end% now display captured moviemovie(gcf,M);18Flow control condition
15、al repetitionwhile-loops are executed repeatedly as long as the evaluates to truewhile endk=1;while prod(1:k)=Inf, k=k+1; enddisp(Largest factorial in Matlab:,num2str(k-1);19Input and OutputX = input(enter your name,s)Y = input(enter your age,a)Disp(X)fprintf(fid,%6.2f n,y)20PlottingPolar plot: t=0:.01:2*pi; polar(t,abs(sin(2*t).*cos(2*t);Line plot:x=0:0.05:5;,y=sin(x.2);,plot(x,y); Stem plot: x = 0:0.1:4;, y = sin(x.2).*exp(-x); stem(x,y)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 44937.5-2025集成电路电磁发射测量第5部分:传导发射测量工作台法拉第笼法
- 中学学生社团活动经费使用效益制度
- 企业内部保密工作流程制度
- 公共交通车辆安全技术检测制度
- 2026年人工智能算法深度学习应用场景题集
- 2026年工程计价与造价分析一级建造师专业试题
- 2026年工程项目管理知识与技能考核试题库
- 2026年英语四六级听力与阅读预测模拟题
- 2026年编程马拉松软件工程与设计能力实践试题库
- 2025年西点展示柜温度监控合同
- 2025年下属辅导技巧课件2025年
- 企业法治建设培训课件
- (一模)郑州市2026年高中毕业年级(高三)第一次质量预测数学试卷(含答案及解析)
- 2026中央广播电视总台招聘124人参考笔试题库及答案解析
- 眼科护理与疼痛管理
- 2026年中国聚苯乙烯行业市场深度分析及发展前景预测报告
- 43-麦肯锡-美的集团绩效管理模块最佳实践分享
- 航空发动机的热管理技术
- 电商平台一件代发合作协议
- 2025年综合行政执法部门招聘《职业能力综合应用能力》模拟试卷及答案
- 学前奥数考试题型及答案
评论
0/150
提交评论