版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 嘉兴南湖学院《药理学与毒理学》2024-2025学年第二学期期末试卷
- 首钢工学院《计算机网络原理与编程》2024-2025学年第二学期期末试卷
- 郑州科技学院《工业大数据分析及应用》2024-2025学年第二学期期末试卷
- 中山大学《DSP系统综合设计》2024-2025学年第二学期期末试卷
- 南宁师范大学《物联网自动识别技术》2024-2025学年第二学期期末试卷
- 深圳信息职业技术学院《创新综合实践》2024-2025学年第二学期期末试卷
- 浙江农林大学《材料工程设计基础》2024-2025学年第二学期期末试卷
- 陕西青年职业学院《艺术学基础》2024-2025学年第二学期期末试卷
- 怀化师范高等专科学校《20世纪西方现代主义文学流派》2024-2025学年第二学期期末试卷
- 2026河北开放大学选聘2人笔试备考试题及答案解析
- 《中药调剂技术》中职全套教学课件
- T-ZSRA 003-2024 特种四足机器人本体通.用技术要求
- 2025年黑龙江省牡丹江市单招职业适应性测试题库及参考答案
- 节后复工复产安全教育培训资料
- 七年级下册语文必背古诗文(字帖描红)
- 危险的毒蘑菇安全教育
- GB/Z 17626.1-2024电磁兼容试验和测量技术第1部分:抗扰度试验总论
- T-GXAS 341-2022 CT血管造影检查护理规范
- 先天性斜颈的临床护理
- 非遗文化介绍课件:篆刻
- 医院培训课件:《医疗纠纷预防和处理条例》
评论
0/150
提交评论