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 Comments

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.
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.

Sign in to comment.

 Accepted Answer

Jan
Jan on 8 May 2012
Such strange error messages can appear, if the folder contains an M-file, whose name equals an M-file of a toolbox you do not have the license for. This happens either by accident or by an illegal copy of a toolbox from another Matlab installation. While I suggest to delete this thread in the later case, you could post a list of file names of the work\ directory, such that other users can detect which file must be renamed.
BTW, this copy protection method seems to be unfriendly to users. There is no chance to understand the problem, if there is a conflict with a file name of a toolbox the user has no copy of. How can such collisions be detected reliably?

3 Comments

Thanks for the reply.
But I think, unfortunatly, that this isn't the solution. Because a list of about a hundred functions and m-files can not all be named accidently the same as MatLab functions.
But in the course of that I tried to 'which' more files. Here comes out, that only in particular folders I got a license problem. The same file saved in another folder works (for now). I'll post soon.
I think we are getting closer...
Having even just *one* .m file named the same thing as a MATLAB function is enough to cause *all* .m files in the folder to have the license problem.
Thank you very much, Walter.
This solved my problem. I did find the files which caused the license problem.

Sign in to comment.

More Answers (5)

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
ragna-b on 7 May 2012
Hello,
Just to point out. These are not my first steps in MatLab. It had all been working well for more than a year. Also on another version of Matlab (R2008b) it works all fine. But suddenly I received these odd messages (at version 7.0.4 Sp2).
I also didn't write the '.m' in the callings. For example I have an m-file 'cc.m'. It only includes: 'clear all; close all; clc;' It can be opened as said. 'Help' is also delivered, but if I want to call it, wherever, I only get one of these to messagelines.

1 Comment

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.

Sign in to comment.

For some further description:
I have a function 'make_new_project' in an added folder.
The command:
>> open make_new_project
opens the file in the editor, as expected. The command:
>> help make_new_project
leads to the output:
'makes a new project, with standard pathnames'
, as requested.
But if I try to run the function with its input arguments:
make_new_project(projectname,path_of_functions)
I only get:
??? Undefined command/function 'make_new_project'
as an output in the command Window. This seems really strange to me.
Thank you Walter. This is what I receive:
>> which -all make_new_project
C:\Programme\MATLAB704\work\make_new_project.m % Has no license available
C:\Programme\MATLAB704\work\...\make_new_project.m % Shadowed , Has no license available
As described above, I tried to copy a file in another folder. There it works (after restarting MatLab with updating the Path Cache). What I receive now is:
>> which -all cc
C:\Programme\MATLAB704\work\cc.m
C:\Programme\MATLAB704\work\functions\cc.m % Shadowed , Has no license available
>> help cc
cc: clc, clear all ,close all
And now it works: entering cc clears the Command Window and the workspace. May that be some problems with the writing rights of the folders? The 'Shadowed' I do understand, but the license problem is strange. May it come from working on different pc's with different MatLab versions?

Categories

Asked:

on 7 May 2012

Community Treasure Hunt

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

Start Hunting!