Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Undefined function or variable - for no reason...

Subject: Undefined function or variable - for no reason...

From: Theophane

Date: 11 Jun, 2010 07:45:10

Message: 1 of 31

Matlab has gone mad! It won't accept any declaration other than predeclared matlab functions (say, fft). Almost any other function call returns 'Undefined function or method bla bla'.

I know you'll think that I don't have the path defined correctly, or that my function is not defined properly, but this is not the case. I am trying to call functions or script located in the directory i am currently browsing.

Tab autocompletes their name when I start typing the first few letters.
But as soon as I press enter, matlab gets confused. I have been using matlab for years, never encountered this problem.

Even weirder, I can copy those files in a different folder, and sometimes, just sometimes, they will work. For a bit. Before becoming un-callable again.

This does not concern all the files I am using, just some. they can be on a different drive, too.

Does anyone have any clue what is going on?

Subject: Undefined function or variable - for no reason...

From: Steven Lord

Date: 11 Jun, 2010 13:34:43

Message: 2 of 31


"Theophane " <theo.weber@hotmail.com> wrote in message
news:huspi6$6ko$1@fred.mathworks.com...
> Matlab has gone mad! It won't accept any declaration other than
> predeclared matlab functions (say, fft). Almost any other function call
> returns 'Undefined function or method bla bla'.
>
> I know you'll think that I don't have the path defined correctly, or that
> my function is not defined properly, but this is not the case. I am trying
> to call functions or script located in the directory i am currently
> browsing.
>
> Tab autocompletes their name when I start typing the first few letters.
> But as soon as I press enter, matlab gets confused. I have been using
> matlab for years, never encountered this problem.
>
> Even weirder, I can copy those files in a different folder, and sometimes,
> just sometimes, they will work. For a bit. Before becoming un-callable
> again.
> This does not concern all the files I am using, just some. they can be on
> a different drive, too.
>
> Does anyone have any clue what is going on?

Send a listing of the names of the files in that directory to Technical
Support so they can investigate what's going on.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Undefined function or variable - for no reason...

From: teki

Date: 10 Aug, 2010 17:23:06

Message: 3 of 31

Hi,

I am facing the same problem today.

I try to run the .m file in my current directory and Matlab would give the message - "Undefined function or variable". I add the current path and still it does not recognize any .m file in the current directory.

Moreover, any new .m file is not running at all, while some of the old .m files I executed previously are working fine.

Any help is most appreciated!

Many thanks,
Sundeep

"Steven Lord" <slord@mathworks.com> wrote in message <hute1f$ifa$1@fred.mathworks.com>...
>
> "Theophane " <theo.weber@hotmail.com> wrote in message
> news:huspi6$6ko$1@fred.mathworks.com...
> > Matlab has gone mad! It won't accept any declaration other than
> > predeclared matlab functions (say, fft). Almost any other function call
> > returns 'Undefined function or method bla bla'.
> >
> > I know you'll think that I don't have the path defined correctly, or that
> > my function is not defined properly, but this is not the case. I am trying
> > to call functions or script located in the directory i am currently
> > browsing.
> >
> > Tab autocompletes their name when I start typing the first few letters.
> > But as soon as I press enter, matlab gets confused. I have been using
> > matlab for years, never encountered this problem.
> >
> > Even weirder, I can copy those files in a different folder, and sometimes,
> > just sometimes, they will work. For a bit. Before becoming un-callable
> > again.
> > This does not concern all the files I am using, just some. they can be on
> > a different drive, too.
> >
> > Does anyone have any clue what is going on?
>
> Send a listing of the names of the files in that directory to Technical
> Support so they can investigate what's going on.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
>

Subject: Undefined function or variable - for no reason...

From: Shanmugam Kannappan

Date: 10 Aug, 2010 17:38:04

Message: 4 of 31

Hi,

May I know how you are trying to run the file?
I mean,r u running in the command window or directly from the m-file.
Also,please check your function name's & variables names are not the same.

Shan!


"teki " <radiotek@gmail.com> wrote in message <i3s1tq$l3n$1@fred.mathworks.com>...
> Hi,
>
> I am facing the same problem today.
>
> I try to run the .m file in my current directory and Matlab would give the message - "Undefined function or variable". I add the current path and still it does not recognize any .m file in the current directory.
>
> Moreover, any new .m file is not running at all, while some of the old .m files I executed previously are working fine.
>
> Any help is most appreciated!
>
> Many thanks,
> Sundeep
>
> "Steven Lord" <slord@mathworks.com> wrote in message <hute1f$ifa$1@fred.mathworks.com>...
> >
> > "Theophane " <theo.weber@hotmail.com> wrote in message
> > news:huspi6$6ko$1@fred.mathworks.com...
> > > Matlab has gone mad! It won't accept any declaration other than
> > > predeclared matlab functions (say, fft). Almost any other function call
> > > returns 'Undefined function or method bla bla'.
> > >
> > > I know you'll think that I don't have the path defined correctly, or that
> > > my function is not defined properly, but this is not the case. I am trying
> > > to call functions or script located in the directory i am currently
> > > browsing.
> > >
> > > Tab autocompletes their name when I start typing the first few letters.
> > > But as soon as I press enter, matlab gets confused. I have been using
> > > matlab for years, never encountered this problem.
> > >
> > > Even weirder, I can copy those files in a different folder, and sometimes,
> > > just sometimes, they will work. For a bit. Before becoming un-callable
> > > again.
> > > This does not concern all the files I am using, just some. they can be on
> > > a different drive, too.
> > >
> > > Does anyone have any clue what is going on?
> >
> > Send a listing of the names of the files in that directory to Technical
> > Support so they can investigate what's going on.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> > To contact Technical Support use the Contact Us link on
> > http://www.mathworks.com
>

Subject: Undefined function or variable - for no reason...

From: teki

Date: 10 Aug, 2010 19:34:04

Message: 5 of 31

Hi Shan,

I tried running the file from both the command window and directly from the m-file but neither works. The function and variable names are not conflicting.

The same function works fine on my pc (with r2008a), but not on my laptop running matlab r2009a. Even a simple m-file to display a message won't run on my laptop now.

On some other pages, someone suggested it might be a problem with the pathdef.m file, but I am not sure...I even added the path of the current directory before running the m-file, but to no avail!

Sundeep

"Shanmugam Kannappan" <shanmugambe@gmail.com> wrote in message <i3s2ps$i16$1@fred.mathworks.com>...
> Hi,
>
> May I know how you are trying to run the file?
> I mean,r u running in the command window or directly from the m-file.
> Also,please check your function name's & variables names are not the same.
>
> Shan!
>
>
> "teki " <radiotek@gmail.com> wrote in message <i3s1tq$l3n$1@fred.mathworks.com>...
> > Hi,
> >
> > I am facing the same problem today.
> >
> > I try to run the .m file in my current directory and Matlab would give the message - "Undefined function or variable". I add the current path and still it does not recognize any .m file in the current directory.
> >
> > Moreover, any new .m file is not running at all, while some of the old .m files I executed previously are working fine.
> >
> > Any help is most appreciated!
> >
> > Many thanks,
> > Sundeep
> >
> > "Steven Lord" <slord@mathworks.com> wrote in message <hute1f$ifa$1@fred.mathworks.com>...
> > >
> > > "Theophane " <theo.weber@hotmail.com> wrote in message
> > > news:huspi6$6ko$1@fred.mathworks.com...
> > > > Matlab has gone mad! It won't accept any declaration other than
> > > > predeclared matlab functions (say, fft). Almost any other function call
> > > > returns 'Undefined function or method bla bla'.
> > > >
> > > > I know you'll think that I don't have the path defined correctly, or that
> > > > my function is not defined properly, but this is not the case. I am trying
> > > > to call functions or script located in the directory i am currently
> > > > browsing.
> > > >
> > > > Tab autocompletes their name when I start typing the first few letters.
> > > > But as soon as I press enter, matlab gets confused. I have been using
> > > > matlab for years, never encountered this problem.
> > > >
> > > > Even weirder, I can copy those files in a different folder, and sometimes,
> > > > just sometimes, they will work. For a bit. Before becoming un-callable
> > > > again.
> > > > This does not concern all the files I am using, just some. they can be on
> > > > a different drive, too.
> > > >
> > > > Does anyone have any clue what is going on?
> > >
> > > Send a listing of the names of the files in that directory to Technical
> > > Support so they can investigate what's going on.
> > >
> > > --
> > > Steve Lord
> > > slord@mathworks.com
> > > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> > > To contact Technical Support use the Contact Us link on
> > > http://www.mathworks.com
> >

Subject: Undefined function or variable - for no reason...

From: Jan Simon

Date: 10 Aug, 2010 20:27:05

Message: 6 of 31

Dear teki,

it would be helpful, if you give us a complete description of what has happened:
1. Did Matlab work fine before?
2. What has happened in between?
3. Does "path" reply the expected toolbox folders?
4. Do you have read access to these folders?
5. Does WHICH find any of the toolbox functions?
6. Are you sure that there are no naming conflicts? If so, why?
7. Does Matlab provide any error messages, if yes, please post them.
8. Further ideas of what might be helpful to identify the problem?

Kind regards, Jan

Subject: Undefined function or variable - for no reason...

From: teki

Date: 10 Aug, 2010 21:10:28

Message: 7 of 31

Hi Jan,

Thanks for your reply. In response to your questions;

1. Matlab worked fine before
2. I discovered this problem four days ago. I had to go back to my desktop to run this function. Today, it worked once when I copied the file from my pc, and saved the file with a different file name on my laptop. I thought that was it, but on subsequent attempts, the m-file would not run.
3. Yes
4. Yes
5. Yes
6. I am quite positive about that. I don't understand why the same m-file runs without any error on my desktop but fails completely on my laptop.
7. Error reads - "undefined function or variable".
8. I am not sure what else can I say about this.

Many thanks,
Sundeep


"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <i3scmp$t6t$1@fred.mathworks.com>...
> Dear teki,
>
> it would be helpful, if you give us a complete description of what has happened:
> 1. Did Matlab work fine before?
> 2. What has happened in between?
> 3. Does "path" reply the expected toolbox folders?
> 4. Do you have read access to these folders?
> 5. Does WHICH find any of the toolbox functions?
> 6. Are you sure that there are no naming conflicts? If so, why?
> 7. Does Matlab provide any error messages, if yes, please post them.
> 8. Further ideas of what might be helpful to identify the problem?
>
> Kind regards, Jan

Subject: Undefined function or variable - for no reason...

From: us

Date: 10 Aug, 2010 22:27:05

Message: 8 of 31

"teki " <radiotek@gmail.com> wrote in message <i3s9jc$85u$1@fred.mathworks.com>...
> Hi Shan,
>
> I tried running the file from both the command window and directly from the m-file but neither works. The function and variable names are not conflicting.
>
> The same function works fine on my pc (with r2008a), but not on my laptop running matlab r2009a. Even a simple m-file to display a message won't run on my laptop now.
>
> On some other pages, someone suggested it might be a problem with the pathdef.m file, but I am not sure...I even added the path of the current directory before running the m-file, but to no avail!
>
> Sundeep

it looks like you might have a broken hd...

us

Subject: Undefined function or variable - for no reason...

From: Walter Roberson

Date: 10 Aug, 2010 22:37:17

Message: 9 of 31

us wrote:
> "teki " <radiotek@gmail.com> wrote in message
> <i3s9jc$85u$1@fred.mathworks.com>...
>> Hi Shan,
>>
>> I tried running the file from both the command window and directly
>> from the m-file but neither works. The function and variable names are
>> not conflicting.
>>
>> The same function works fine on my pc (with r2008a), but not on my
>> laptop running matlab r2009a. Even a simple m-file to display a
>> message won't run on my laptop now.
>>
>> On some other pages, someone suggested it might be a problem with the
>> pathdef.m file, but I am not sure...I even added the path of the
>> current directory before running the m-file, but to no avail!
>>
>> Sundeep
>
> it looks like you might have a broken hd...

Or a corrupted Matlab installation.

I'd probably start by removing the matlab preferences file.

Subject: Undefined function or variable - for no reason...

From: Jan Simon

Date: 10 Aug, 2010 23:22:21

Message: 10 of 31

Dear teki,

> 7. Error reads - "undefined function or variable".

Please copy the complete message. Sometimes there is a subtle difference between the exact message and the thing one means to have read (sorry, I have the strong impression, that this is not English anymore - I want to say:
While it is in general a good idea to think before posting, for error messages it is the other way around: post instead of thinking.).

Something strange happens, so a tiny detail may carry the important hint.

Jan

Subject: Undefined function or variable - for no reason...

From: teki

Date: 10 Aug, 2010 23:43:07

Message: 11 of 31

Thanks Us and Walter! My hd is fine but I suspect something's wrong with matlab as Walter suggests..

Jan, the exact error message when I try to run (e.g. 'filename.m') reads as:
??? Undefined function or variable 'filename'.

Thanks,
Sundeep



"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <i3smvd$e62$1@fred.mathworks.com>...
> Dear teki,
>
> > 7. Error reads - "undefined function or variable".
>
> Please copy the complete message. Sometimes there is a subtle difference between the exact message and the thing one means to have read (sorry, I have the strong impression, that this is not English anymore - I want to say:
> While it is in general a good idea to think before posting, for error messages it is the other way around: post instead of thinking.).
>
> Something strange happens, so a tiny detail may carry the important hint.
>
> Jan

Subject: Undefined function or variable - for no reason...

From: Øyvind

Date: 17 Sep, 2010 09:06:06

Message: 12 of 31

Did anyone ever find a solution to this? I am having the exact same problem. Tried reinstalling matlab, but no luck.

When I find a folder that works, every script works in that folder. So everytime I start Matlab I have to find a folder that works (totally random each time) and move all my scripts to that folder.

I use Matlab R2010 and Windows 7. I installed Matlab on my D: drive instead of C:, I don't know if that is making Matlab confused. But I have found folders on both my C and my D drive that works.

Subject: Undefined function or variable - for no reason...

From: Jeremy Lagorse

Date: 22 Sep, 2010 10:37:05

Message: 13 of 31

I had the same problem. It seems that if there is a function in your folder that has the same name of a matlab function (even if it is a function from a pakcage that you did not install), you can have this problem.

The only solution that I found to avoid this problem is to rename all the functions in the folder by adding my name at the end of the function (for instance "yourfunction.m" is then renamed with "yourfunction_yourname.m").

Please, let me know if this worked!

Thanks.

Jeremy

"Øyvind " <oyvdahl@online.no> wrote in message <i6vb1u$36j$1@fred.mathworks.com>...
> Did anyone ever find a solution to this? I am having the exact same problem. Tried reinstalling matlab, but no luck.
>
> When I find a folder that works, every script works in that folder. So everytime I start Matlab I have to find a folder that works (totally random each time) and move all my scripts to that folder.
>
> I use Matlab R2010 and Windows 7. I installed Matlab on my D: drive instead of C:, I don't know if that is making Matlab confused. But I have found folders on both my C and my D drive that works.

Subject: Undefined function or variable - for no reason...

From: Øyvind

Date: 23 Sep, 2010 06:09:05

Message: 14 of 31

I think I have the same problem. I have some functions with the same name as some functions from the Neural Network Package. No functions in that folder will work.

But if I move the contents of that folder to a different folder after Matlab is started, it works.

Oyvind


"Jeremy Lagorse" <jeremy.lagorse@veolia.com> wrote in message <i7cm8g$mms$1@fred.mathworks.com>...
> I had the same problem. It seems that if there is a function in your folder that has the same name of a matlab function (even if it is a function from a pakcage that you did not install), you can have this problem.
>
> The only solution that I found to avoid this problem is to rename all the functions in the folder by adding my name at the end of the function (for instance "yourfunction.m" is then renamed with "yourfunction_yourname.m").
>
> Please, let me know if this worked!
>
> Thanks.
>
> Jeremy
>

Subject: Undefined function or variable - for no reason...

From: Shai

Date: 7 Apr, 2011 16:03:05

Message: 15 of 31

"Øyvind" wrote in message <i7equ0$1g3$1@fred.mathworks.com>...
> I think I have the same problem. I have some functions with the same name as some functions from the Neural Network Package. No functions in that folder will work.
>
> But if I move the contents of that folder to a different folder after Matlab is started, it works.
>
> Oyvind
>
>
> "Jeremy Lagorse" <jeremy.lagorse@veolia.com> wrote in message <i7cm8g$mms$1@fred.mathworks.com>...
> > I had the same problem. It seems that if there is a function in your folder that has the same name of a matlab function (even if it is a function from a pakcage that you did not install), you can have this problem.
> >
> > The only solution that I found to avoid this problem is to rename all the functions in the folder by adding my name at the end of the function (for instance "yourfunction.m" is then renamed with "yourfunction_yourname.m").
> >
> > Please, let me know if this worked!
> >
> > Thanks.
> >
> > Jeremy
> >

Have you tried
>> rehash
or
>> rehash path
??
seems to work for me (but I'm not 100% certain)

Subject: Undefined function or variable - for no reason...

From: nick

Date: 29 Jun, 2011 00:55:10

Message: 16 of 31

"Shai " <shai.bagon@weizmann.ac.il> wrote in message <inkn7p$fbi$1@fred.mathworks.com>...
> "Øyvind" wrote in message <i7equ0$1g3$1@fred.mathworks.com>...
> > I think I have the same problem. I have some functions with the same name as some functions from the Neural Network Package. No functions in that folder will work.
> >
> > But if I move the contents of that folder to a different folder after Matlab is started, it works.
> >
> > Oyvind
> >
> >
> > "Jeremy Lagorse" <jeremy.lagorse@veolia.com> wrote in message <i7cm8g$mms$1@fred.mathworks.com>...
> > > I had the same problem. It seems that if there is a function in your folder that has the same name of a matlab function (even if it is a function from a pakcage that you did not install), you can have this problem.
> > >
> > > The only solution that I found to avoid this problem is to rename all the functions in the folder by adding my name at the end of the function (for instance "yourfunction.m" is then renamed with "yourfunction_yourname.m").
> > >
> > > Please, let me know if this worked!
> > >
> > > Thanks.
> > >
> > > Jeremy
> > >
>
> Have you tried
> >> rehash
> or
> >> rehash path
> ??
> seems to work for me (but I'm not 100% certain)

Subject: Undefined function or variable - for no reason...

From: Hye Young

Date: 23 Mar, 2012 21:00:34

Message: 17 of 31

I have exactly a same problem!!


"Nick" wrote in message <iudt5e$9q5$1@newscl01ah.mathworks.com>...
> "Shai " <shai.bagon@weizmann.ac.il> wrote in message <inkn7p$fbi$1@fred.mathworks.com>...
> > "Øyvind" wrote in message <i7equ0$1g3$1@fred.mathworks.com>...
> > > I think I have the same problem. I have some functions with the same name as some functions from the Neural Network Package. No functions in that folder will work.
> > >
> > > But if I move the contents of that folder to a different folder after Matlab is started, it works.
> > >
> > > Oyvind
> > >
> > >
> > > "Jeremy Lagorse" <jeremy.lagorse@veolia.com> wrote in message <i7cm8g$mms$1@fred.mathworks.com>...
> > > > I had the same problem. It seems that if there is a function in your folder that has the same name of a matlab function (even if it is a function from a pakcage that you did not install), you can have this problem.
> > > >
> > > > The only solution that I found to avoid this problem is to rename all the functions in the folder by adding my name at the end of the function (for instance "yourfunction.m" is then renamed with "yourfunction_yourname.m").
> > > >
> > > > Please, let me know if this worked!
> > > >
> > > > Thanks.
> > > >
> > > > Jeremy
> > > >
> >
> > Have you tried
> > >> rehash
> > or
> > >> rehash path
> > ??
> > seems to work for me (but I'm not 100% certain)

Subject: Undefined function or variable - for no reason...

From: Di

Date: 30 May, 2012 10:37:06

Message: 18 of 31

Hi Theopane,
Did you figure this out? I also encountered this bizarre problem this morning, and I have not found a solution. Any help would be greatly appreciated.
Thanks in advance,
Di

"Theophane " <theo.weber@hotmail.com> wrote in message <huspi6$6ko$1@fred.mathworks.com>...
> Matlab has gone mad! It won't accept any declaration other than predeclared matlab functions (say, fft). Almost any other function call returns 'Undefined function or method bla bla'.
>
> I know you'll think that I don't have the path defined correctly, or that my function is not defined properly, but this is not the case. I am trying to call functions or script located in the directory i am currently browsing.
>
> Tab autocompletes their name when I start typing the first few letters.
> But as soon as I press enter, matlab gets confused. I have been using matlab for years, never encountered this problem.
>
> Even weirder, I can copy those files in a different folder, and sometimes, just sometimes, they will work. For a bit. Before becoming un-callable again.
>
> This does not concern all the files I am using, just some. they can be on a different drive, too.
>
> Does anyone have any clue what is going on?

Subject: Undefined function or variable - for no reason...

From: Øyvind

Date: 30 May, 2012 11:11:06

Message: 19 of 31

You cannot have the same function name as an already existing matlab function (either built-in or from one of the libraries). It doesn't matter if you don't have the respective library installed.

I had this problem and couldn't figure it out before I contacted Matlab support.

Subject: Undefined function or variable - for no reason...

From: John D'Errico

Date: 30 May, 2012 12:29:08

Message: 20 of 31

"Øyvind" wrote in message <jq4v8a$21u$1@newscl01ah.mathworks.com>...
> You cannot have the same function name as an already existing matlab function (either built-in or from one of the libraries). It doesn't matter if you don't have the respective library installed.
>
> I had this problem and couldn't figure it out before I contacted Matlab support.

In fact, this is a false statement.

For example, I do NOT have the image processing toolbox
so imshow does not exist.

>> which imshow
'imshow' not found.

I can define a variable with that name.

>> imshow = 7
imshow =
     7

clear imshow

Now, try creating an imshow function.

>> edit imshow
>> type imshow

function imshow
disp('Gosh, it works fine')

Now, test the code out.

>> imshow
Gosh, it works fine

John

Subject: Undefined function or variable - for no reason...

From: Øyvind

Date: 30 May, 2012 13:30:12

Message: 21 of 31

John:
You are right, it is possible to have the same name and make it work. BUT it is also a chance that this will produce errors that are hard to figure out.

Here is an explanation: http://www.mathworks.com/support/solutions/en/data/1-3NP7VQ/index.html

Oyvind

Subject: Undefined function or variable - for no reason...

From: John D'Errico

Date: 30 May, 2012 14:09:09

Message: 22 of 31

"Øyvind" wrote in message <jq57d4$8be$1@newscl01ah.mathworks.com>...
> John:
> You are right, it is possible to have the same name and make it work. BUT it is also a chance that this will produce errors that are hard to figure out.
>
> Here is an explanation: http://www.mathworks.com/support/solutions/en/data/1-3NP7VQ/index.html
>
> Oyvind

Of course. Name conflicts are always a potential problem. But
it is silly to expect me to know every possible toolbox, and
every existing function name in every toolbox I do not own.

MATLAB does NOT have a problem with me naming a function
something even though they have already used that name in
some toolbox I've never seen or intend to use. That would be
insane.

In fact, I can happily name a function with the same name
as an existing function, as long as I am cognizant of what
I've done, and take care that it does not cause a problem.
Yes, this is dangerous, and even often foolish, but still
possible.

John

Subject: Undefined function or variable - for no reason...

From: Star Strider

Date: 30 May, 2012 16:19:14

Message: 23 of 31

"Øyvind" wrote in message <jq57d4$8be$1@newscl01ah.mathworks.com>...
> John:
> You are right, it is possible to have the same name and make it work. BUT it is also a chance that this will produce errors that are hard to figure out.
>
> Here is an explanation: http://www.mathworks.com/support/solutions/en/data/1-3NP7VQ/index.html
>
> Oyvind

------------------------------------------------------------------------------------------

I'm not quite sure what the problem here turned out to be or how you or TMW solved it, but many, many versions ago when MATLAB first created the ‘MATLAB’ directory under ‘Documents’ (on Windows systems), I added the following code to the beginning of my ‘startup.m’ (in ‘toolbox\local’) and have never had problems since (unless I created a new subdirectory while I was running MATLAB and forgot to tell MATLAB about it). The code could probably be improved, and updated to take advantage of new features and syntax, but since it only needs to run once when I launch MATLAB, and it still runs correctly, I haven't changed it significantly unless changes in MATLAB versions required them. (I have all my user files and data collected in a single ‘Documents\MATLAB\’ subdirectory ‘My_Files’ and its subdirectories.)

To use it, change the ‘workfiles = 'My_Files';’ line to the subdirectory name you use. MATLAB will find and run new ‘.m’ files and find new data files created while MATLAB is running if they’re somewhere in an existing subdirectory of ‘My_Files’.


% ================== START ‘ADD WORK FILES TO PATH’ ==================

pathmat = path;

findpath = strfind(pathmat,'\MATLAB');

firstpath = [pathmat(1,1:findpath(1)+6) '\'];

firstpathdir = dir(firstpath);

dirnamemat = char(firstpathdir.name);

for k1 = 1:size(dirnamemat,1)
    if isdir(dirnamemat(k1,:)) && isempty(findstr(dirnamemat(k1,:),'.'))
        workpath = [firstpath dirnamemat(k1,:) '\'];
        workdir = deblank(dirnamemat(k1,:));
    end
end

workfiles = 'My_Files'; % Subdirectory and its subdirectories under 'Documents\MATLAB\' where I have my user files

newpath = genpath(workdir);

scanpath = textscan(newpath,'%s','Delimiter',';');

charpath = char(scanpath{:});

for k1 = 1:size(charpath,1)
    filepath(k1,:) = [firstpath '\' charpath(k1,:)];
end

for k1 = 1:size(charpath,1)
% fprintf(1,'\t%3d %s\n',k1,filepath(k1,:))
    addpath(filepath(k1,:),1)
end

fprintf(1,'\n\t\tWORK FILES "%s" ADDED TO “MATLABPATH” ... \n', workfiles);

% ================== END OF ‘ADD WORK FILES TO PATH’ ==================

Subject: Undefined function or variable - for no reason...

From: Ben Lange

Date: 9 Feb, 2013 18:20:14

Message: 24 of 31

I experienced this issue in the following scenario.

Initially I named my .m file HW1.m, it worked fine.
I then renamed my .m file to be HW1-NearestNeighboar.m.

I experienced the dreaded Undefined function or variable error.

I then changed the - to _ and everything worked fine.

Apparenly, MatLab doesn't support - characters in the *.m filename.

Subject: Undefined function or variable - for no reason...

From: Steven_Lord

Date: 11 Feb, 2013 03:36:33

Message: 25 of 31



"Ben Lange" <blange3@gmail.com> wrote in message
news:kf640u$rn0$1@newscl01ah.mathworks.com...
> I experienced this issue in the following scenario.
>
> Initially I named my .m file HW1.m, it worked fine.
> I then renamed my .m file to be HW1-NearestNeighboar.m.
>
> I experienced the dreaded Undefined function or variable error.
>
> I then changed the - to _ and everything worked fine.
>
> Apparenly, MatLab doesn't support - characters in the *.m filename.

That is correct.

http://www.mathworks.com/help/matlab/matlab_prog/create-functions-in-files.html

"Valid function names follow the same rules as variable names. They must
start with a letter, and can contain letters, digits, or underscores."

If function names were allowed to contain a minus sign, this:

HW1-NearestNeighboar(1)

would be ambiguous -- it could be either a call to the function you wrote or
the result of subtracting the first element of the array NearestNeighboar
from the variable HW1.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Undefined function or variable - for no reason...

From: anyone

Date: 11 Feb, 2013 20:18:00

Message: 26 of 31

On Sun, 10 Feb 2013 22:36:33 -0500, Steven_Lord wrote:

> "Ben Lange" <blange3@gmail.com> wrote in message
> news:kf640u$rn0$1@newscl01ah.mathworks.com...
>> I experienced this issue in the following scenario.
>>
>> Initially I named my .m file HW1.m, it worked fine.
>> I then renamed my .m file to be HW1-NearestNeighboar.m.
>>
>> I experienced the dreaded Undefined function or variable error.
>>
>> I then changed the - to _ and everything worked fine.
>>
>> Apparenly, MatLab doesn't support - characters in the *.m filename.
>
> That is correct.
>
> http://www.mathworks.com/help/matlab/matlab_prog/create-functions-in-files.html
>
> "Valid function names follow the same rules as variable names. They must
> start with a letter, and can contain letters, digits, or underscores."
>
> If function names were allowed to contain a minus sign, this:
>
> HW1-NearestNeighboar(1)
>
> would be ambiguous -- it could be either a call to the function you
> wrote or the result of subtracting the first element of the array
> NearestNeighboar from the variable HW1.

so what he -really- needs is software that will do what he means, not what he says.

Subject: Undefined function or variable - for no reason...

From: Rafa

Date: 12 Nov, 2013 16:41:12

Message: 27 of 31

Hi all,

I'm having the same problem here. In my case, functions don't run when they are part of a class folder (i.e. starting with '@'). So I have the strange behaviour:

>> which -all ttm
/home/rafa/tensor_toolbox/@ttensor/ttm.m % ttensor method
/home/rafa/tensor_toolbox/@tensor/ttm.m % tensor method
/home/rafa/tensor_toolbox/@sptensor/ttm.m % sptensor method
/home/rafa/tensor_toolbox/@ktensor/ttm.m % ktensor method
>> ttm
Undefined function or variable 'ttm'.

('ttm' is a perfectly valid file from a widely-used toolbox, it used to work until it randomly broke, and the '/home/rafa/tensor_toolbox/' folder belongs to the path, as it should be)

In general, a lot of confusion seems to exist around these 'undefined' error issues. Anyone has any clue?

Walter Roberson <roberson@hushmail.com> wrote in message <i3skbg$c6q$1@canopus.cc.umanitoba.ca>...
> us wrote:
> > "teki " <radiotek@gmail.com> wrote in message
> > <i3s9jc$85u$1@fred.mathworks.com>...
> >> Hi Shan,
> >>
> >> I tried running the file from both the command window and directly
> >> from the m-file but neither works. The function and variable names are
> >> not conflicting.
> >>
> >> The same function works fine on my pc (with r2008a), but not on my
> >> laptop running matlab r2009a. Even a simple m-file to display a
> >> message won't run on my laptop now.
> >>
> >> On some other pages, someone suggested it might be a problem with the
> >> pathdef.m file, but I am not sure...I even added the path of the
> >> current directory before running the m-file, but to no avail!
> >>
> >> Sundeep
> >
> > it looks like you might have a broken hd...
>
> Or a corrupted Matlab installation.
>
> I'd probably start by removing the matlab preferences file.

Subject: Undefined function or variable - for no reason...

From: Steven Lord

Date: 12 Nov, 2013 20:49:41

Message: 28 of 31


"Rafa " <rafael.ballesterripoll@uzh.ch> wrote in message
news:l5tln8$s74$1@newscl01ah.mathworks.com...
> Hi all,
> I'm having the same problem here. In my case, functions don't run when
> they are part of a class folder (i.e. starting with '@'). So I have the
> strange behaviour:
>
>>> which -all ttm
> /home/rafa/tensor_toolbox/@ttensor/ttm.m % ttensor method
> /home/rafa/tensor_toolbox/@tensor/ttm.m % tensor method
> /home/rafa/tensor_toolbox/@sptensor/ttm.m % sptensor method
> /home/rafa/tensor_toolbox/@ktensor/ttm.m % ktensor method
>>> ttm
> Undefined function or variable 'ttm'.
>
> ('ttm' is a perfectly valid file from a widely-used toolbox, it used to
> work until it randomly broke, and the '/home/rafa/tensor_toolbox/' folder
> belongs to the path, as it should be)
>
> In general, a lot of confusion seems to exist around these 'undefined'
> error issues. Anyone has any clue?

Note that all four of those function paths have a comment "<something>
method" at the end? That means they are class methods and you MUST call them
with an instance of that class for at least one of the inputs (unless
they're Static methods, in which case you need to call them using the name
of the class.)

http://www.mathworks.com/help/matlab/matlab_oop/specifying-methods-and-functions.html

If those methods are NOT Static, you would need to call them with at least
one ttensor object as input (in which case the first method is called), a
tensor object as input (second method), a sptensor object (third), or a
ktensor (fourth.) Your call with 0 inputs doesn't give ANY of those objects
as input, so MATLAB doesn't know which method to call and so doesn't call
any of them. Since there's no non-method function named ttm visible to
MATLAB (it would have shown up in the WHICH output if there were) it
correctly says essentially "I don't know what you want me to do."

If they were Static and accepted 0 inputs, you would call them as:

ttensor.ttm()
tensor.ttm()
sptensor.ttm()
ktensor.ttm()

The help for those methods should indicate the correct way to call them.

help ttensor.ttm

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Undefined function or variable - for no reason...

From: Yilin

Date: 28 Jan, 2014 01:23:07

Message: 29 of 31

Hi everyone. I'm having a similar issue and I don't have duplicated function name in my working directory. There are only have two self-created functions 'functest' and 'funcone'. 'functest' is created after I started my current matlab. 'funcone' is created from last time. However, 'funcone' is not running. 'functest' is fine. I have tried reinstall matlab. The problem still exists. Do I have to create a new function every time ??
Any help is much appreciated.

EDU>> pwd
ans =
C:\Users\DESKTOP\Documents\MATLAB

EDU>> dir
. .. funcone.m functest.m

EDU>> which -all funcone
C:\Users\DESKTOP\Documents\MATLAB\funcone.m

EDU>> funcone(1)
Undefined function 'funcone' for input arguments of type 'double'.

EDU>> which -all functest
C:\Users\DESKTOP\Documents\MATLAB\functest.m

EDU>> functest(1)
ans =
     2


"Theophane " <theo.weber@hotmail.com> wrote in message <huspi6$6ko$1@fred.mathworks.com>...
> Matlab has gone mad! It won't accept any declaration other than predeclared matlab functions (say, fft). Almost any other function call returns 'Undefined function or method bla bla'.
>
> I know you'll think that I don't have the path defined correctly, or that my function is not defined properly, but this is not the case. I am trying to call functions or script located in the directory i am currently browsing.
>
> Tab autocompletes their name when I start typing the first few letters.
> But as soon as I press enter, matlab gets confused. I have been using matlab for years, never encountered this problem.
>
> Even weirder, I can copy those files in a different folder, and sometimes, just sometimes, they will work. For a bit. Before becoming un-callable again.
>
> This does not concern all the files I am using, just some. they can be on a different drive, too.
>
> Does anyone have any clue what is going on?

Subject: Undefined function or variable - for no reason...

From: Steven Lord

Date: 28 Jan, 2014 15:21:42

Message: 30 of 31


"Yilin " <chyylq@gmail.com> wrote in message
news:lc70pr$og0$1@newscl01ah.mathworks.com...
> Hi everyone. I'm having a similar issue and I don't have duplicated
> function name in my working directory. There are only have two
> self-created functions 'functest' and 'funcone'. 'functest' is created
> after I started my current matlab. 'funcone' is created from last time.
> However, 'funcone' is not running. 'functest' is fine. I have tried
> reinstall matlab. The problem still exists. Do I have to create a new
> function every time ?? Any help is much appreciated.
> EDU>> pwd
> ans =
> C:\Users\DESKTOP\Documents\MATLAB
>
> EDU>> dir
> . .. funcone.m functest.m
> EDU>> which -all funcone
> C:\Users\DESKTOP\Documents\MATLAB\funcone.m
>
> EDU>> funcone(1)
> Undefined function 'funcone' for input arguments of type 'double'.

Show the group the contents of funcone.m. Is it a function file, a script
file, a class file, or not a MATLAB program file at all? [Just because it
has the extension doesn't mean it's guaranteed to be a MATLAB program file.]

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Undefined function or variable - for no reason...

From: Yilin

Date: 29 Jan, 2014 02:41:07

Message: 31 of 31

For my case, it is 'user error'. I do have a dup file name. When I started to remove each file one by one out of my current directory yesterday, I didn't restart Matlab after I removed them so Matlab still thought I had conflicting file in the directory. 'functest.m' was created and ran successfully after I kept only 'funcone.m'.

Given the huge amount of views on this post, it will be really helpful even if Mathwork can do a proper error message with conflicting file names as part of the output. Thank you.


"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <lc8hu6$1hn$1@newscl01ah.mathworks.com>...
>
> "Yilin " <chyylq@gmail.com> wrote in message
> news:lc70pr$og0$1@newscl01ah.mathworks.com...
> > Hi everyone. I'm having a similar issue and I don't have duplicated
> > function name in my working directory. There are only have two
> > self-created functions 'functest' and 'funcone'. 'functest' is created
> > after I started my current matlab. 'funcone' is created from last time.
> > However, 'funcone' is not running. 'functest' is fine. I have tried
> > reinstall matlab. The problem still exists. Do I have to create a new
> > function every time ?? Any help is much appreciated.
> > EDU>> pwd
> > ans =
> > C:\Users\DESKTOP\Documents\MATLAB
> >
> > EDU>> dir
> > . .. funcone.m functest.m
> > EDU>> which -all funcone
> > C:\Users\DESKTOP\Documents\MATLAB\funcone.m
> >
> > EDU>> funcone(1)
> > Undefined function 'funcone' for input arguments of type 'double'.
>
> Show the group the contents of funcone.m. Is it a function file, a script
> file, a class file, or not a MATLAB program file at all? [Just because it
> has the extension doesn't mean it's guaranteed to be a MATLAB program file.]
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us