EXACT same function, just different name. One has error "input arguments of type double", why?

Hello, I am new to Mathlab. I am taking a course that requires me to turn in my .m files (scripts and functions) with the file name lastname_first_function.m When I write a function, let's say this simple one calcarea.m
function [area] = calcarea(rad)
%calcarea calculates area of a circle
% Format of call: calcarea(radius)
area = 2*pi*rad;
end
compared to my turn in one last_first_calcarea.m
function [area] = last_first_calcarea(rad)
%calcarea calculates area of a circle
% Format of call: calcarea(radius)
area = 2*pi*rad;
end
The error I receive is "Undefined function 'last_first_calcarea' for input arguments of type 'double'."
Funny thing is that I sometimes do not get the error, but most of time, especially when I have longer functions/scripts, I get this error. The files are exactly the same, in the same directory, only thing is that their file names are different as well as their name in the m. file. What is causing the error, or is there any way to override it? Thanks

댓글 수: 2

Yes, I have made sure to rename both the primary function and the actual m file to last_first_calcarea.m Error still shows up
Hi,
Are you sure your .m file and the function are named the same way? It shouldn't fail if thats correct. I mean, if your function is
function [area] = my_function(rad) ...
your .m file must be named "my_function.m". Otherwise it won't find the function when you call it from the workspace.

댓글을 달려면 로그인하십시오.

답변 (1개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

Joe
2013년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by