User Defined Functions calling

1 view (last 30 days)
Hariharan Sundaram
Hariharan Sundaram on 2 Dec 2020
Hello experts,
Am creating a user defined function, like the below with a file name as (myfunc.m)
function outcome = myfunc(x, a, b, c)
outcome = 2*(x.^2) + 3*x + a + b + c ;
end
Calling it in the another program with file name Prog1.m
for n = 1:5
x = n*0.1;
z = myfunc(x,2,3,7);
fprintf('x = %4.2f f(x) = %8.4f \r',x,z)
end
Am using the latest version of MATLAB, 2020, would like to know if any errors or modification needed in the code to correct it.
  4 Comments
Hariharan Sundaram
Hariharan Sundaram on 2 Dec 2020
We get the below as an error
>> prog1
Error: File: myfunc.m Line: 3 Column: 20
Local function name must be different from the script name.Error in prog1 (line 7)
z = myfunc(x,2,3,7);
Is it because both the scripts (function myfunc & calling prog1) are in same folder?

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!