Is it possible to set a function within one m file and use that function in matlab?
1 view (last 30 days)
Show older comments
Jong Rok Lee
on 16 May 2019
Commented: Jong Rok Lee
on 20 May 2019
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)
0 Comments
Accepted Answer
Walter Roberson
on 16 May 2019
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.
5 Comments
Walter Roberson
on 16 May 2019
What is not possible in MATLAB is a function definition in the middle of a script. It is possible to define a function in the middle of a function.
function drive_my_car
N1=1; N2=100;
function summation(N1,N2)
x=0;
for ct=N1:N2
x=x+ct;
end
end
summation(N1,N2)
end
More Answers (0)
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!