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 myfunction.m.
function y = myfunction(x) y = x.^2 + x;
This function requires input x.
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.
Run the function by clicking Run or a specific run command from the drop-down list. For myfunction.m, and an input of 1:10, this result appears in the Command Window:
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.