Undefined command/function
显示 更早的评论
Hello,
if have a problem to start/ run my selfwritten .m-files. First of all, I added the path where the m.-files are saved by 'Set path'. They are there in the list. I can also open the files by 'open example.m'. But if they are called in another m-file, I always receive:
'??? Undefined command/function example.m'
If I want to run the files via commandline I receive:
??? Undefined function or variable 'example.m'
as an error message.
Thanks for your help
2 个评论
Walter Roberson
2012-5-7
You should never include the '.m' in invoking a function or script. The exception to that is that if you use run() for a script, the .m can be included in the path name.
Jan
2012-5-7
Please include a copy of the failing command in postings in this forum. It is a rare case, that the cause of an error can be guessed only based on the error message.
采纳的回答
更多回答(5 个)
Jan
2012-5-7
Omit the ".m" on the name of the function.
If the file is called "example.m" and starts with a function definition like e.g.:
function [out1, out2] = example(in1, in2)
...
then you have to call it like:
[a, b] = example(23, 17)
Such basic details are explained in the Getting Stared chapters of the documentation. It is recommended to take the time to read them, because they are fundamental for using such a high-power environment like Matlab.
ragna-b
2012-5-7
0 个投票
1 个评论
Jan
2012-5-8
Then it would have been a good idea to explain such details in the original post already. It wastes the time of yourself and of the contributors in this forum, if the details have to be guessed.
The error message '??? Undefined command/function example.m' cannot appear if you try to call "example()". Please post an exact copy of the error message in the future to increase the chance to get helpful answers.
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!