Undefined command/function
Show older comments
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 Comments
Walter Roberson
on 7 May 2012
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
on 7 May 2012
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.
Accepted Answer
More Answers (5)
Jan
on 7 May 2012
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
on 7 May 2012
0 votes
1 Comment
Jan
on 8 May 2012
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.
ragna-b
on 7 May 2012
1 Comment
Walter Roberson
on 7 May 2012
What does
which -all make_new_project
show?
ragna-b
on 8 May 2012
ragna-b
on 8 May 2012
Categories
Find more on Startup and Shutdown 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!