Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Undefined function or variable - for no reason...

224 views
Skip to first unread message

Theophane

unread,
Jun 11, 2010, 3:45:10 AM6/11/10
to
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?

Steven Lord

unread,
Jun 11, 2010, 9:34:43 AM6/11/10
to

"Theophane " <theo....@hotmail.com> wrote in message
news:huspi6$6ko$1...@fred.mathworks.com...

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


teki

unread,
Aug 10, 2010, 1:23:06 PM8/10/10
to
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" <sl...@mathworks.com> wrote in message <hute1f$ifa$1...@fred.mathworks.com>...

Shanmugam Kannappan

unread,
Aug 10, 2010, 1:38:04 PM8/10/10
to
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 " <radi...@gmail.com> wrote in message <i3s1tq$l3n$1...@fred.mathworks.com>...

teki

unread,
Aug 10, 2010, 3:34:04 PM8/10/10
to
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" <shanm...@gmail.com> wrote in message <i3s2ps$i16$1...@fred.mathworks.com>...

Jan Simon

unread,
Aug 10, 2010, 4:27:05 PM8/10/10
to
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

teki

unread,
Aug 10, 2010, 5:10:28 PM8/10/10
to
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.T...@nMINUSsimon.de> wrote in message <i3scmp$t6t$1...@fred.mathworks.com>...

us

unread,
Aug 10, 2010, 6:27:05 PM8/10/10
to
"teki " <radi...@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

Walter Roberson

unread,
Aug 10, 2010, 6:37:17 PM8/10/10
to

Or a corrupted Matlab installation.

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

Jan Simon

unread,
Aug 10, 2010, 7:22:21 PM8/10/10
to
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

teki

unread,
Aug 10, 2010, 7:43:07 PM8/10/10
to
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.T...@nMINUSsimon.de> wrote in message <i3smvd$e62$1...@fred.mathworks.com>...

Øyvind

unread,
Sep 17, 2010, 5:06:06 AM9/17/10
to
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.

Jeremy Lagorse

unread,
Sep 22, 2010, 6:37:05 AM9/22/10
to
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 " <oyv...@online.no> wrote in message <i6vb1u$36j$1...@fred.mathworks.com>...

Øyvind

unread,
Sep 23, 2010, 2:09:05 AM9/23/10
to
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....@veolia.com> wrote in message <i7cm8g$mms$1...@fred.mathworks.com>...

Shai

unread,
Apr 7, 2011, 12:03:05 PM4/7/11
to
"Øyvind" wrote in message <i7equ0$1g3$1...@fred.mathworks.com>...

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

Nick

unread,
Jun 28, 2011, 8:55:10 PM6/28/11
to
"Shai " <shai....@weizmann.ac.il> wrote in message <inkn7p$fbi$1...@fred.mathworks.com>...

Hye Young

unread,
Mar 23, 2012, 5:00:34 PM3/23/12
to
I have exactly a same problem!!


"Nick" wrote in message <iudt5e$9q5$1...@newscl01ah.mathworks.com>...

Di

unread,
May 30, 2012, 6:37:06 AM5/30/12
to
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....@hotmail.com> wrote in message <huspi6$6ko$1...@fred.mathworks.com>...

Øyvind

unread,
May 30, 2012, 7:11:06 AM5/30/12
to
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.

John D'Errico

unread,
May 30, 2012, 8:29:08 AM5/30/12
to
"Ø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

Øyvind

unread,
May 30, 2012, 9:30:12 AM5/30/12
to
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

John D'Errico

unread,
May 30, 2012, 10:09:09 AM5/30/12
to
"Øyvind" wrote in message <jq57d4$8be$1...@newscl01ah.mathworks.com>...
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

Star Strider

unread,
May 30, 2012, 12:19:14 PM5/30/12
to
"Øyvind" wrote in message <jq57d4$8be$1...@newscl01ah.mathworks.com>...
------------------------------------------------------------------------------------------

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’ ==================

Ben Lange

unread,
Feb 9, 2013, 1:20:14 PM2/9/13
to
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.

Steven_Lord

unread,
Feb 10, 2013, 10:36:33 PM2/10/13
to


"Ben Lange" <bla...@gmail.com> wrote in message
news:kf640u$rn0$1...@newscl01ah.mathworks.com...
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
sl...@mathworks.com

anyone

unread,
Feb 11, 2013, 3:18:00 PM2/11/13
to
On Sun, 10 Feb 2013 22:36:33 -0500, Steven_Lord wrote:

> "Ben Lange" <bla...@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.

Rafa

unread,
Nov 12, 2013, 11:41:12 AM11/12/13
to
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 <robe...@hushmail.com> wrote in message <i3skbg$c6q$1...@canopus.cc.umanitoba.ca>...

Steven Lord

unread,
Nov 12, 2013, 3:49:41 PM11/12/13
to

"Rafa " <rafael.ball...@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
sl...@mathworks.com

Yilin

unread,
Jan 27, 2014, 8:23:07 PM1/27/14
to
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

Steven Lord

unread,
Jan 28, 2014, 10:21:42 AM1/28/14
to

"Yilin " <chy...@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.]

Yilin

unread,
Jan 28, 2014, 9:41:07 PM1/28/14
to
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" <Steve...@mathworks.com> wrote in message <lc8hu6$1hn$1...@newscl01ah.mathworks.com>...

chao

unread,
Mar 30, 2015, 9:20:11 PM3/30/15
to
"Theophane " <theo....@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?


hi,
i have the same problem previously, and now it works. Maybe my filefolder name is not normal, eg, include some special symbol, "*", "!", and so on. if you use name which does not have these special symbol, it may be done.

chao

unread,
Mar 30, 2015, 9:33:12 PM3/30/15
to
"Yilin " <chy...@gmail.com> wrote in message <lc9po3$dft$1...@newscl01ah.mathworks.com>...
Hi,
i have the same preblem previously, and now it works. maybe my filefolder name include some special symbols, eg "*", "!", and so on. When i rename my Matlab folder name(not have these special symbols), my problem has been done. it is just a suggestion, maybe this method works.

echokilocharlie

unread,
May 5, 2015, 12:15:58 PM5/5/15
to
"Theophane " <theo....@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?

I too had this problem, and changing one of my function names to something that is apparently not available in a toolbox fixed it. My question is...is there somewhere we can get a listing of every Matlab function that exists, both built-in and in all toolboxes? I'm not sure how we are supposed to know all the function names that exist in toolboxes for which we don't have access.

vizwiz

unread,
Aug 11, 2015, 6:14:13 AM8/11/15
to
I ran into this problem this morning. The source of my problem was slightly different. I am on a network license where toolboxes are shared. I was trying to use the function resample.m and kept getting the error message that resample.m was undefined. Initially I was baffled as typing 'edit resample.m' brought up the file. Double checking the toolbox paths also showed everything in order. Only after typing 'which resample.m' did I notice that matlab gave the message: '

C:\Program Files\MATLAB\R2015a\toolbox\signal\signal\resample.m % Has no license available'

So I just have to wait for the license to free up on the network.
However, it should be said that some matlab toolboxes are written in such a way that they also repeat filenames for example resample.m in toolbox directories for signal processing & time series analysis, which results in the undefined message.

As others have mentioned it would be much more useful to have a verbose message that states your license is not available or tell you that multiple functions have the same names



"echokilocharlie" wrote in message <miaqbn$au5$1...@newscl01ah.mathworks.com>...

Alexey

unread,
Mar 15, 2016, 7:48:15 PM3/15/16
to
Also had this issue today for the first time. The reason was that I added a new function to my loop and that function did addpath of a folder that completely overshadowed my functions (as it is an older version of the same folder). So the code even looked fairly close, but upon closer inspection was broken.

The moral: step through the code and make sure no unexpected addpath/rmpath happen. Also, check the path to file that you are debugging (it is shown in blue Editor ribbon) - you might be debugging a wrong version of the file.

Shoaib Khan

unread,
Jun 21, 2016, 4:24:09 AM6/21/16
to
"Alexey" wrote in message <nca6vj$kbi$1...@newscl01ah.mathworks.com>...
> Also had this issue today for the first time. The reason was that I added a new function to my loop and that function did addpath of a folder that completely overshadowed my functions (as it is an older version of the same folder). So the code even looked fairly close, but upon closer inspection was broken.
>
> The moral: step through the code and make sure no unexpected addpath/rmpath happen. Also, check the path to file that you are debugging (it is shown in blue Editor ribbon) - you might be debugging a wrong version of the file.


Hi Alex,
I am having same problem of undefined error. The reason I found is that I am calling another script (.m) file in current script. Does calling a another script overwrites the variable of current script in work space. Both are in same folder.
When I don't call another script the code works fine.why?

Steven Lord

unread,
Jun 21, 2016, 9:15:09 AM6/21/16
to


"Shoaib Khan" <shoai...@stud.fh-flensburg.de> wrote in message
news:nkatj3$fkc$1...@newscl01ah.mathworks.com...
It's impossible to tell without seeing the code, but my guess is that the
"another script" has the three C's (unnecessarily) at the top: close all,
clear all, clc. A common tendency among newer users of MATLAB is to put
these at the top of EVERY script file they write.

"close all" closes figure windows; annoying if you want to compare the
figures from multiple runs of the same script with slightly modified
parameters.

"clc" clears the Command Window; as with "close all", this is annoying if
you want to compare results printed by multiple runs of the same script with
different parameters.

"clear all" clears all the variables in the workspace. At best it does
nothing; at worst it may destroy a result that took hours or days to
compute. Hope you saved your workspace into a MAT-file before clearing!

I recommend getting in the habit of using these commands sparingly, only
when you know you have a specific need for them.

Md.Mobasshir Arshed

unread,
Jul 3, 2016, 3:44:10 AM7/3/16
to
"vizwiz" wrote in message <mqchtb$o8h$1...@newscl01ah.mathworks.com>...
hello can u tell me how do u get rid of this problem??thanks

Ishan Naktode

unread,
Feb 15, 2017, 9:23:07 PM2/15/17
to
MATLAB is just a shitty software.
I don't know why people brag about it.
Always returning 'Undefined functions'.

In my case.

imfinfo and imshow are working but the imnoise function isn't while they belong to the same image processing toolbox.

thalia

unread,
Mar 1, 2017, 1:26:16 PM3/1/17
to
Hello guys,
I had the same issue with my function defined INSIDE the main m file I was running. However I was getting
"Undefined function or variable 'detrend_data_pol'"
Two points:
- Restart Matlab solved my problem
- and if you have defined the function (myfunction.m) within a script/or another function (main.m) and you try to evaluate myfunction.m. matlab does not see it. You have to run the main function/script for your function to be run as well.

Megan Jones

unread,
Mar 1, 2017, 8:07:08 PM3/1/17
to
"Theophane" 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?

Make sure that the function you're currently working on is saved to the MATLAB folder that matlab creates in your computer! I often fail to call functions only to realize that the function I'm working on is only saved to my desktop, and not that folder. That explains why matlab knows to use previous functions you worked on too- it's because they're located in the MATLAB folder
0 new messages