Presentation is loading. Please wait.

Presentation is loading. Please wait.

Objective: To be able to create script and function files

Similar presentations


Presentation on theme: "Objective: To be able to create script and function files"— Presentation transcript:

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

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

3 M-files t=0:0.1:10 y=sin(t) plot(t,y) function [y]=fplot2(t) y=sin(t)
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 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 function y=fplot(t) y=sin(t);
create an m-file and save it as fplot.m FILE New M-file function y=fplot(t) y=sin(t); Open M-file MATLAB Command Window >> 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 end
If (x>0) f=x^2 else f=0 end

8 for loops General form: special case for index=initial: limit
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


Download ppt "Objective: To be able to create script and function files"

Similar presentations


Ads by Google