MATLAB Answers

I’m using uncontrol check box , by command in a script, I have associated a function with check box, how can I get the handle of that function out

Muhammad Jibran 님이 질문을 제출함. 3 Jan 2019
uicontrol('style', 'checkbox', 'string', 'plz tick', 'callback',{@dt,xm};
function h = dt(hObject,xm,~)
h = line([xm xm] , [-1 1])
end
%%% I want to have the handle of line h , in my script as i click on check box

  댓글 수: 5

표시 이전 댓글 수: 2
Have you looked at the answer below?
YeS i trtried bbut could not be done.
Let me share my objective.
I have a a simpe graph, say sine wave. Using uicontrol i added a check box on the above-mentioned sinwave figure. Now on check box click/unclick a vertical line appears/disppears on figure.
I wanwant to have handle of this line to slide it on the sinewave figure.
Once the callback function returns, its workspace is cleared. The ouputs of a callback don't go anywhere and are ignored. So if you want to get something out, you will have to save it somewhere. Then you could retrieve it back from that location in the function where you need to use that handle. You can save the handle using the UserData property, the guiddata function, or setappdata/getappdata. You could also edit the Tag property of the line object, so you can search for it.
What did you try, and why do you think it failed?

로그인 to comment.

태그

답변 수: 1

Michael C. 님의 답변 3 Jan 2019

If I were doing something like this, I woudl do one of two things:
% Add this line inside "dt" function
set(hObject,'UserData',h)
% Use this to pull the line handle back into scope when you need it
% (this assumes that there is only one check box with the string 'plz tick')
hLine = get(findobj('String','plz tick'),'UserData')
or make a change to your "line" call
h = line([xm xm] , [-1 1],'Tag','myLine');
Then use
% Use this to pull the line handle back into scope
hLine = findobj('Tag','myLine');
In the second option, you might need to be a little careful depending on how the 'NextPlot' property is set on the axes you are plotting to as you could get into the situation where you end up with vector of handles to a lot of lines.
It looks like your callback might have the last two inputs swapped as well. I think it should be "function h = dt(hObject,~,xm,)"

  댓글 수: 1

i have already used the suggested code, but it did not work. Moreover, i did used sepapp data, the same problem pursisted. kindly guide me to used guide data

로그인 to comment.



Translated by