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

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…

Contents