Enter your Sign on user name and password.

Forgot password?
Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of MATLAB
  • Discussion

  • Study Guides

  • Practice Questions

  • Download Lecture Slides

  • Table of Contents

  • Related Books

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Sign up for Educator.com

Membership Overview

  • Unlimited access to our entire library of courses.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lesson files for programming and software training practice.
  • Track your course viewing progress.
  • Download lecture slides for taking notes.
  • Learn at your own pace... anytime, anywhere!

Function M-Files, Part 3

  • In the early versions of MATLA there was a clear distinction between command and function but now both of them are saves similarly. As a general rule, commands change the environment and functions have some output.
  • MATLAB has a very powerful debugging tool, you can basically have the program stopped at any point and see what your arguments are and then check if the function has done a correct job or no.

Function M-Files, Part 3

Write and test a function swop(x, y) which will exchange the values of its two input arguments.
function [xout, yout] = swop(x, y)
xout = y;
yout = x;
Write and test a function double(x) which doubles its input argument, i.e. the statement x = double(x) should double the value in x.
function y = double(x)
y = 2 * x;
The Fibonacci numbers are generated by the sequence 1,1,2,3,5,8,13,.... Can you work out the next  term? Write a recursive function f(n) to compute the Fibonacci numbers to the 30th term. Using the following relationship:
Fn = Fn−1 + Fn−2, given F0 = F1 = 1
function y = f(n)
f(1) = 1;
f(2) = 1;

for i = 3:n
    f(i) = f(i-1) + f(i-2);


*These practice questions are only helpful when you work on them offline on a piece of paper and then use the solution steps function to check your answer.


Function M-Files, Part 3

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Feval 2:00
  • Example: Rewriting Procedure as Newton Function 2:35
    • Defining Function
  • Overview: How to Use Function 5:43
  • Command/Function Duality 6:18
    • Example
  • Debugging a Script 7:22
  • Breakpoint Alley 8:02
  • Debugging a Function 10:09