From the course: Learning MATLAB
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Create and use a function with one input - MATLAB Tutorial
From the course: Learning MATLAB
Create and use a function with one input
- [Instructor] Functions in MATLAB contain one or more sequential comments. They accept inputs and return outputs. To create a function go to New and then select Function. An untitled function file will open. A function, like the script, is saved as a .m file. Let's look at the syntax of functions in MATLAB. A function begins with a function definition line, which is the first line here, that contains input and output arguments. The outputs are the variables whose values are calculated by the function using the input values. The output arguments are enclosed in square brackets and the input arguments are enclosed in parenthesis. It is important to note here that the name of the function which is Untitled 17 now, will also be the name of the file when you save the function file. The comment section here is not mandatory to run the function, but it is good practice to describe what we are doing with this function. The first…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Writing a program8m 37s
-
(Locked)
If/else statements5m 11s
-
(Locked)
For loops5m 46s
-
(Locked)
While loops3m 51s
-
(Locked)
Create and use a function with one input5m 3s
-
(Locked)
Create and use a function with two inputs4m 55s
-
(Locked)
Challenge: Write your first program2m 31s
-
(Locked)
Solution: Write your first program8m 14s
-
-
-