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 个评论
Joe
2013-3-12
Jaime Muela Pérez
2013-3-12
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 个)
Image Analyst
2013-3-12
What does this show:
>> which -all last_first_calcarea
类别
在 帮助中心 和 File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!