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

サインインしてコメントする。

 採用された回答

Jan
Jan 2012 年 5 月 8 日

1 投票

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 件のコメント

ragna-b
ragna-b 2012 年 5 月 8 日
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...
Walter Roberson
Walter Roberson 2012 年 5 月 8 日
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.
ragna-b
ragna-b 2012 年 5 月 9 日
Thank you very much, Walter.
This solved my problem. I did find the files which caused the license problem.

サインインしてコメントする。

その他の回答 (5 件)

Jan
Jan 2012 年 5 月 7 日

0 投票

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 2012 年 5 月 7 日

0 投票

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 件のコメント

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

サインインしてコメントする。

ragna-b
ragna-b 2012 年 5 月 7 日

0 投票

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.

1 件のコメント

Walter Roberson
Walter Roberson 2012 年 5 月 7 日
What does
which -all make_new_project
show?

サインインしてコメントする。

ragna-b
ragna-b 2012 年 5 月 8 日

0 投票

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
ragna-b
ragna-b 2012 年 5 月 8 日

0 投票

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?

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2012 年 5 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by