Left - Rigth - double click on a plo
5 views (last 30 days)
Show older comments
Hi guys,
I am confuse using the get(fig,'SelectionType').
What I want to do is really simple:
if get(fig,'SelectionType') == 'open';
do an operation
elseif get(fig,'SelectionType') == 'alt'
do another operation
end
as simple as that, but I have not been able to do it.
thanks for your help
carlos
0 Comments
Answers (2)
Jan
on 10 Nov 2012
Edited: Jan
on 10 Nov 2012
get(fig,'SelectionType') replies a string. This is a vector of type char. When you compare two vectors, they must have the same length:
'123' == '1234' % ERROR!
To compare strings, use strcmp:
if strcmp(get(fig,'SelectionType'), 'open')
or a switch block:
switch get(fig,'SelectionType')
case 'open'
...
otherwise
warning('SelectionType not caught')
end
2 Comments
Jan
on 10 Nov 2012
"Is not working" is a bad description of a problem. Please explain the necessary details ever, in every case, under all circumstances. I cannot guess, why in "get(F1, 'SelectionType')" the variable F1 seems to be the figure handle, while in "F1(3)" F1 seems to be a vector.
Matt Fig
on 10 Nov 2012
Edited: Matt Fig
on 10 Nov 2012
Look at this example for how to use this property.
function [] = figselect()
% Click in the axes
figure('windowbuttondownfcn',@fwbdfcn)
axes
function [] = fwbdfcn(varargin)
if strcmp('alt',get(gcbf,'selectiontype'))
disp('Alt used')
else
disp('Alt not used')
end
.
.
.
. EDIT
Here is a more interactive form. Either left or right click on any of the dots. Note that one might want to put more checks on gco.
function [] = figselect()
figure('windowbuttondownfcn',@fwbdfcn)
[X,Y,Z] = cylinder(1,500);
plot(X(1,:),Y(1,:))
hold on
for ii = 1:10
plot(rand,rand,'*k')
end
axis square
function [] = fwbdfcn(varargin)
if strcmp(get(gco,'type'),'axes')
return
end
if strcmp('alt',get(gcbf,'selectiontype'))
delete(gco)
else
set(gco,'color','r')
end
0 Comments
See Also
Categories
Find more on Bounding Regions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!