matlab GUI: How to access the name/tag of a function?

조회 수: 4 (최근 30일)
Dominic Noel Kluck
Dominic Noel Kluck 2023년 5월 8일
댓글: Dominic Noel Kluck 2023년 5월 17일
I have over 30 push buttons in a GUI which all shoud behave the same. Therefore I want to create an external function. Furthermore I need to access the name/tag of the function connected to the desired push button. Here is an example code which is automatically created by Matlab after creating a push button in a GUI:
function push_X_Callback(hObject, eventdata, handles)
X represents any possible occuring number from 1 to 37 which is why I need to get acces to the function name "push_X_Callback" which I then can get the "X" from.
Thanks in advance
Dominic

채택된 답변

Steven Lord
Steven Lord 2023년 5월 8일
If they all behave exactly the same, why not give them the exact same callback function? The first input to the callback is the object whose callback is executing.
"Graphics callback functions must accept at least two input arguments:
  • The graphics object whose callback is executing — Use this argument within your callback function to refer to the object.
  • The event data structure — Use this argument within your callback function to access information about the user action that is specific to the callback property and the object. This structure is empty for many graphics object callbacks."
  댓글 수: 2
Walter Roberson
Walter Roberson 2023년 5월 8일
To expand slightly:
Once you have the graphics object that the callback is about (because it is the first parameter to the callback) then you can ask to get the Tag property of the object.
this_tag = hObject.Tag;
Dominic Noel Kluck
Dominic Noel Kluck 2023년 5월 17일
Thank you both very much!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by