1 / 8

SE207 Lab 2

SE207 Lab 2. Objective: To be able to create script and function files. MATLAB Files. Two types of files: SCRIPT files FUNCTION files Both have the extension .m [ M-files] (file1.m, f2.m). SCRPT Files: a list of MATLAB instructions saved on a file for convenience no input argument

joellem
Download Presentation

SE207 Lab 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SE207 Lab 2 Objective: To be able to create script and function files

  2. MATLAB Files • Two types of files: • SCRIPT files • FUNCTION files • Both have the extension .m [ M-files] (file1.m, f2.m)

  3. SCRPT Files: a list of MATLAB instructions saved on a file for convenience no input argument The variables are global FUNCTION files Starts with “FUNCTION “ statement that specifies the input and output arguments Local variables Treated as the built-in functions M-files t=0:0.1:10 y=sin(t) plot(t,y) function [y]=fplot2(t) y=sin(t) plot(t,y)

  4. Function M-files • create an m-file and save it as fplot.m • MATLAB Command Window FILE New M-file function y=fplot(t) y=sin(t); Open M-file >>t=0:0.1:10 >> z=fplot(t) >> plot(t,z)

  5. MATRIX OPERATIONS • Transpose A’ • inverse inv(A) • determinant det(A) • rank rank(A)

  6. Special functions • Exponential exp(x) • square root sqrt(x) • natural logarithm log(x) • common logarithm log10(x) • absolute value abs(x) more details Use help to know related functions

  7. If structures General form: If condition statements else statements end If (x>0) f=x^2 else f=0 end

  8. for loops General form: for index=initial: increment: limit statements end special case if increment is 1 for index=initial: limit for i=1:100 x(i)=sin(i*.2) end

More Related