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!