Calling App designer function from .m script

25 次查看(过去 30 天)
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.
Situation:
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 =
@(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event)
Any help appreciated, thank you,
David

采纳的回答

TADA
TADA 2021-9-9
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 个评论
TADA
TADA 2021-9-9
actually this:
gui.ReadErrorButton.ButtonPushedFcn([], []);
might work as well, depending on how you wrote the callback function
David Cervinek
David Cervinek 2021-9-12
Helo TADA,
thanks for feedback, it does work...it seems that I made a typo as well as put wrong parameters in brackets.
Once again, thanks and have a nice day,
David

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by