Left - Rigth - double click on a plo
이전 댓글 표시
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
답변 (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
Carlos
2012년 11월 10일
Jan
2012년 11월 10일
"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
카테고리
도움말 센터 및 File Exchange에서 Bounding Regions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!