Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Rik
am 6 Jan. 2019
Bearbeitet: Rik
am 6 Jan. 2019
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?
Antworten (1)
Michael C.
am 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 Kommentar
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!