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개)

Jan
Jan 2012년 11월 10일
편집: Jan 2012년 11월 10일

0 개 추천

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

Ok, I guess I am doing something wrong with the handlers.
I set-up a figure with two reference vectors.
F1=figure('Color',[1 1 1]);
axes1 = axes('Parent',F1,'FontSize',16);
F1(1)=plot(time,xdata, '-or');hold on
F1(2)=plot(time,xdata1,'-og');
Then I have a collection of points that I want to check in the figure using the just plotted reference vector: Point1, point2, point3, ..., pointN
points=[xcoordinate1 ycoordinate1
xcoordinate2 ycoordinate2
...
xcoordinateN ycoordinateN]
This matrix has a size of N by 2
My idea is to check (point by point) in the plot if the points are in the place (location) where I want them to be. If the point is where I want it to be,I should double click in the figure and this action should plot the point in yellow. If the point is 'wrong', i want to press the left mouse click and this should delete the point.
I thought to do something like this. But obviously is wrong...
for X=1:size(points,1)
F(3)=plot(points(X,1), points(X,2),'or')
switch get(F1,'SelectionType')
case 'open'
F1(3)= plot(point(1), point(2), 'oy') %%plot the point in yellow as an indication is 'Right'
case 'alt'
delete(F1(3)) %%delete the point, it is wrong.
otherwise
warning('SelectionType not caught')
end
end
But this is not working, I am confuse with the use of the handlers. I guess !!!
Jan
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.

댓글을 달려면 로그인하십시오.

Matt Fig
Matt Fig 2012년 11월 10일
편집: Matt Fig 2012년 11월 10일

0 개 추천

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에 대해 자세히 알아보기

질문:

2012년 11월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by