Left - Rigth - double click on a plo
Mostrar comentarios más antiguos
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
Respuestas (2)
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 comentarios
Carlos
el 10 de Nov. de 2012
Jan
el 10 de Nov. de 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.
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
Categorías
Más información sobre Bounding Regions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!