필터 지우기
필터 지우기

Calling App designer function from .m script

조회 수: 44 (최근 30일)
David Cervinek
David Cervinek 2021년 9월 9일
댓글: David Cervinek 2021년 9월 12일
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