필터 지우기
필터 지우기

Matlab simulink access to gui handle in listener

조회 수: 1 (최근 30일)
Adrien
Adrien 2012년 1월 13일
댓글: Ram Kripal Singh 2016년 1월 2일
Hello,
I have a problem with my gui program which pilot a simulink model.
On my Gui program (made with GUIDE) I have an add_exec_event_listener function that link a simulink block (Scope) with a Gui function.
In the Gui function, I want to collect the input value of the scope block (That works well) and save it in my Gui handle. But I can't have access to the Gui handle. Even if I use
hf = findall(0,'tag',mfilename)
guidata(hf);
In Matlab command line I have this error :
hf =
Empty matrix: 0-by-1
??? Error using ==> guidata at 89
H must be the handle to a figure or figure descendent.
Error in ==> IM20_Starter>localEventListener at 362
ad = guidata(hf)
Thank for your help and excuse my limited English
  댓글 수: 1
Eyad
Eyad 2012년 9월 2일
Hi I'm trying to make a GUI to control a model on a RTW ,I made the GUI with GUIDE and set the strartfcn of the model to "localAddEventListener" , the model and GUI works perfectly on simulation but when I build it on XPC target box and try to press connect it gives me an error saying that it can't find the function .I removed the function "localAddEventListener" from the callback of the model's startfcn and added it through the GUI after building and connecting the model to the XPC ,the simulation worked perfectly , but when i tried to run it on the XPC it didn't show an error but no data was displayed , as you said the event listeners probably weren't invoked on the XPC, what do you think caused that ? and how do I solve it ?

댓글을 달려면 로그인하십시오.

채택된 답변

Titus Edelhofer
Titus Edelhofer 2012년 1월 13일
Hi,
if the GUI is programmed with GUIDE, you should be able to collect the handles by just calling the gui again. If your gui is called mygui, you should be able to get the handles by
hFigure = mygui();
handles = guidata(hFigure);
Titus
  댓글 수: 2
Adrien
Adrien 2012년 1월 13일
Thank you very much
it works very very well.
I didn't know that the name of my Gui return object handle
Thank
Titus Edelhofer
Titus Edelhofer 2012년 1월 13일
Your welcome. If you like you might mark the question as "answered" ...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adrien
Adrien 2012년 1월 13일
I have an answer but it's not a realy clean way. I use a Global variable for my handle. In my function AddEventListener, I declare my Handle in Global like:
global ad;
% get the application data
ad = guidata(gcbo);
Then in my Even Listener function:
global ad; // put ad in global to re-use it
  댓글 수: 1
Ram Kripal Singh
Ram Kripal Singh 2016년 1월 2일
The Answer by Adrien is better as it is faster and more efficient.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by