Calling App designer function from .m script

72 visualizaciones (últimos 30 días)
David Cervinek
David Cervinek el 9 de Sept. de 2021
Comentada: David Cervinek el 12 de Sept. de 2021
Hello guys,
first to describe the situation: I have GUI made in App Designer and Matlab .m script. These two are working together and trading variables without issues.
My problem is that I would like to call function which is in AppDesigner from .m script file.
From GUI user presses button which will initiate communication to actuator.
This communication will be then processed by the .m script
I would then like to call function in AppDesigner which would take the received data from script and use them.
I was not able to find this problem anywhere, I only found it solved from other direction (calling script/function from AppDesigner)
I did try this:
gui = GUI;
gui.ReadErrorButton.ButtonPushedFcn(); -> ERROR: Unrecognized method, property, or field 'ReadErrorButton' for class 'GUI'.
I get this information when I check for the function during debugging:
val =
Any help appreciated, thank you,

Respuesta aceptada

TADA el 9 de Sept. de 2021
App designer GUIs are not a separate application, App Designer simply generates matlab classes and wraps them in an mlapp file for some project management reason or whatever (obscurity in my opinion, but nevermind that).
as such, you can do with AppDes GUI objects whatever you can do with any other matlab handle object, under some restrictions, since the code isn't exacly editable (for a good reason, still).
So you can calll GUI properties and functions from matlab script and vice versa, there should be no problem with that.
Notice that the error particularly mentions the button doesn't exist
"ERROR: Unrecognized method, property, or field 'ReadErrorButton' for class 'GUI'."
my guess is you named it something different and therefore, cannot access this gui.ReadErrorButton because it actually doesn't exist.
Once you resolve this, you should be able to call the callback function via the ButtonPushedFcn property of the button, but you will also need to specify the two callback parameters (src, eventData)
gui.ReadErrorButton.ButtonPushedFcn(gui.ReadErrorButton, event.EventData);
again, if you use the real name of the button, the above invocation of the callback function should work.
to change the button name, you can find the button in the Component Browser when you open your app in App Designer,
when you find it, right click it, and rename it to "ReadErrorButton" (or left click it in the component browser and click F12)
  2 comentarios
TADA el 9 de Sept. de 2021
actually this:
gui.ReadErrorButton.ButtonPushedFcn([], []);
might work as well, depending on how you wrote the callback function
David Cervinek
David Cervinek el 12 de Sept. de 2021
Helo TADA,
thanks for feedback, it does seems that I made a typo as well as put wrong parameters in brackets.
Once again, thanks and have a nice day,

Iniciar sesión para comentar.

Más respuestas (0)


Más información sobre Environment and Settings en Help Center y File Exchange.




Community Treasure Hunt

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

Start Hunting!

Translated by