Unrecognized function or variable 'max'.

17 views (last 30 days)
I am facing an issue while using Matlab app designer.
It seems that when I am using App designer, it is giving the following error "unrecognised function or variable ''max"' for 'max'.
but when I use it in workspace without opening the app. It works fine. I have attached 2 screenshots for reference, one with app paused in debugger, other without opening the app.
And these lines of codes were working fine before, started giving problems from last 2 days.
I am not generating any variable named max within the app.
I tried both MATLAB 2021b and 2022b, same problem persists
What kind of problem this is?
Have a nice day ahead.
  10 Comments
Geoff Hayes
Geoff Hayes on 26 Sep 2022
Is that the mlapp file or does that include supporting files?
RITAM BASU
RITAM BASU on 26 Sep 2022
the mlapp file is small but it needs big data file to plot (and replicate the issue)..
I have asked my colleague to have a look in his computer. Maybe will be able to get a reply by tomorrow.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 27 Sep 2022
Edited: Walter Roberson on 27 Sep 2022
Somewhere in that function, or in a function that the function is nested within, you assigned to a variable named "max". In doing so, you signalled to MATLAB that everywhere within scope, that max is to be treated as a variable. Even if you later cleared max so that whos does not see it and which shows you the MATLAB function, the fact that the name existed as a variable prevents max from being used as a function name within the same scope.
It is not permitted for the same name to refer to both a variable and a function. If the first reference to max within a scope is using it as a function then you will get an error if you try to assign to max as a variable; if the first reference to max within a scope is using it as a variable then you get exactly this kind of odd error where it mysteriously cannot be used as a function even after the variable is cleared.
When you leave the scope that this occurs in, the restriction no longer holds and max suddenly starts working as a function again.
Moral of the story: using max or sum as the name of a variable are especially likely to get you into trouble, confusion over whether the name is a function or a variable.
  3 Comments
Torsten
Torsten on 29 Sep 2022
Edited: Torsten on 29 Sep 2022
But you use a structure with name "max" because you refer to "max.speed". This won't work together with the max function.
Maybe you meant "max_speed" instead of "max.speed" ?
RITAM BASU
RITAM BASU on 29 Sep 2022
Ofcourse... found it at last. It was a typo. Now works fine..
Thanks a lot man for looking into it...
Have a nice day..

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 26 Sep 2022
>> restoredefaultpath
  4 Comments
RITAM BASU
RITAM BASU on 26 Sep 2022
maxValue =
4.
I got it normal.
Not really. no clear calls.
Image Analyst
Image Analyst on 27 Sep 2022
I agree with Walter below. You defined max somewhere. Then you stopped at a breakpoint and, in the command window, said "clear all" so that blew away your max. When you tried to use max after that, it said that it didn't know what max was anymore. Of course, since you cleared it. Clear all will get rid of private variables and functions but not built-in ones. But because your private max overrode the built-in one, it no longer knows about the built-in max. When you cleared your private max, it evidently does not automatically restore the definition of max to the built-in one.
You didn't answer if you searched everywhere for max. Search for max and then reply with every single line where max is mentioned. Don't leave any out.

Sign in to comment.

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!