Unrecognized function or variable 'max'.

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 comentarios

Geoff Hayes
Geoff Hayes el 26 de Sept. de 2022
@RITAM BASU - can you attach the code for your GUI?
RITAM BASU
RITAM BASU el 26 de Sept. de 2022
Editada: RITAM BASU el 26 de Sept. de 2022
Thanks for your interest.
(new) variables I created to debug the issue.
app.filename_char_out is the line where I got error originally.
new1 is a (1*32) double.
The interesting thing is that, I stopped it in debugger, defined new variables and tried to find the max. It did not work then but when I closed the app and tried to generate same variables and get the max, I got it . you can check the snapshots of the original question for better understanding.
So it seems that somehow max function stopps working when using app designer, which is very weird. And these same codes were working fine some days ago.
%%% creating the model specific output filename (part) here (to be used in
%%% export plots function while exporting the final plots). Done so
%%% that we dont need to generate variables again just to generate the
%%% filname.
% new1 = num2str(ceil(max(data.val_per_speed_nom(3,:))/num_inverter));
new1 = (data.val_per_speed_max(3,:));
new2 = max(new1);
new3 = ceil(new2);
new3 = num2str(ceil(max(data.val_per_speed_max(3,:))/num_inverter));
app.filename_char_out = strcat(single_result{1,1}.Design_values.Design_name,'_char_motor_',num2str(Udc),'Vdc_',num2str(ceil(max(data.val_per_speed_nom(3,:))/num_inverter)),'Aac_',num2str(ceil(max(data.val_per_speed_max(3,:))/num_inverter)),'Aac');
app.filename_eff_out = strcat(single_result{1,1}.Design_values.Design_name,'_eff_mot_',num2str(Udc),'Vdc_',num2str(ceil(max(data.val_per_speed_nom(3,:))/num_inverter)),'Aac_',num2str(ceil(max(data.val_per_speed_max(3,:))/num_inverter)),'Aac_',num2str(mod_factor*100),'Mod');
app.filename_excel_out = strcat(single_result{1,1}.Design_values.Design_name,'_mot_',num2str(Udc),'Vdc_',num2str(ceil(max(data.val_per_speed_nom(3,:))/num_inverter)),'Aac_',num2str(ceil(max(data.val_per_speed_max(3,:))/num_inverter)),'Aac_',num2str(mod_factor*100),'Mod','.xlsx');
When running your code and you pause it in the debugger, what happens if you run the following from the command line
k>> which max
What is the result of this call?
RITAM BASU
RITAM BASU el 26 de Sept. de 2022
I got this
built-in (C:\Program Files\MATLAB\R2022b\toolbox\matlab\datafun\max)
attached a snapshot also
Geoff Hayes
Geoff Hayes el 26 de Sept. de 2022
Editada: Geoff Hayes el 26 de Sept. de 2022
What happens if you do the same but type
>> pwd
to check the current working directory? You can do this before or after you have launched your app too so that we can see if there is a change in the path.
RITAM BASU
RITAM BASU el 26 de Sept. de 2022
it remains same.
attached screenshot
Geoff Hayes
Geoff Hayes el 26 de Sept. de 2022
Can you attach your GUI so that we can try to reproduce the issue?
RITAM BASU
RITAM BASU el 26 de Sept. de 2022
the zip file is 33mb.. It is not allowing to share it here..
Geoff Hayes
Geoff Hayes el 26 de Sept. de 2022
Is that the mlapp file or does that include supporting files?
RITAM BASU
RITAM BASU el 26 de Sept. de 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.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Sept. de 2022
Editada: Walter Roberson el 27 de Sept. de 2022

0 votos

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 comentarios

RITAM BASU
RITAM BASU el 29 de Sept. de 2022
Thanks a lot for your thoughts. @Walter Roberson. @Image Analyst, @Geoff Hayes
I understand your point. But I checked it thoroughly and it seems like that this is not the case.
It is giving error only inside a function, the error starts popping up from the first line it enters the function.
I dont understand why is it happening.
I have attached the .mlapp file and concerned function "plot_characteristic_standalone_new1".
please open the .mlapp file, run and click on plot. I have put a breakpoint before line 703 in the app, and in the first line in the function script. you can check where the max function is working. Will you be able to check the issue and give me some insight? That would be very helpful.
Thanks a lot for your time and support guys. Have a nice day ahead.
PS- there is a force close button in the app, to close the app.!
Torsten
Torsten el 29 de Sept. de 2022
Editada: Torsten el 29 de Sept. de 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 el 29 de Sept. de 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..

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 26 de Sept. de 2022

1 voto

>> restoredefaultpath

4 comentarios

RITAM BASU
RITAM BASU el 26 de Sept. de 2022
tried this.. then opened the app and ran it. Got same error.
Do you have any calls to "clear" anywhere in your program?
Search everywhere in your program for "max". Examine every single line where max is mentioned to see that it look okay.
Do this in the command window immediately after starting MATLAB:
v = [1,2,3,4];
maxValue = max(v)
What do you see?
RITAM BASU
RITAM BASU el 26 de Sept. de 2022
maxValue =
4.
I got it normal.
Not really. no clear calls.
Image Analyst
Image Analyst el 27 de Sept. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 26 de Sept. de 2022

Comentada:

el 29 de Sept. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by