MATLAB: Is it possible to set a function within one m file and use that function in matlab

function

In Python, we can set a function and use function at a same file.
then,Is it possible to set a function within one m file and use that function in matlab?
for example, i want to make summantion function like this,
clear all; close all; clc
N1=1; N2=100;
function summation(N1,N2)
x=0;
for ct=N1:N2
x=x+ct;
end
end
summation(N1,N2)

Best Answer

Yes. The function definition must be after the script calling it, and the name of the script cannot be the same as the name of the function.