This example shows how to run a function that requires some initial setup, such as input argument values, while working in the Editor.
Create a function in a program file named
function y = myfunction(x) y = x.^2 + x;
This function requires input
View the commands available for running the function by clicking Run on the Editor tab. The command at the top of the list is the command that the Editor uses by default when you click the Run icon.
Replace the text type code to run with an expression that allows you to run the function.
y = myfunction(1:10)
You can enter multiple commands on the same line, such as
x = 1:10; y = myfunction(x)
For more complicated, multiline commands, create a separate script file, and then run the script.
Note: Run commands use the base workspace. Any variables that you define in a run command can overwrite variables in the base workspace that have the same name.
Run the function by clicking Run or
a specific run command from the drop-down list. For
and an input of
1:10, this result appears in the
y = 2 6 12 20 30 42 56 72 90 110
When you select a run command from the list, it becomes the default for the Run button.
To edit or delete an existing run command, select the command, right-click, and then select Edit or Delete.