Calling App designer function from .m script
36 ビュー (過去 30 日間)
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:
Any help appreciated, thank you,
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)
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)