Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
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
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Rik
2019년 1월 6일
편집: Rik
2019년 1월 6일
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?
답변 (1개)
Michael C.
2019년 1월 3일
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
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!