Coordinates related to rbbox in GUI

1 view (last 30 days)
Lin
Lin on 17 May 2011
I programmed a GUI where there is a Axes in it. I try to select some objects in this Axes using rbbox.
The problem is that the return vector of rbbox is measured from the coordinate of whole GUI instead of the coordinate of Axes. How can I get the return vector whos reference coordinate is Axes in Gui?
Thank you in advance. Lin

Accepted Answer

Matt Fig
Matt Fig on 17 May 2011
You could just do like the example in RBBOX, and use the currentpoint property of the axes instead...
figure;
pcolor(peaks);
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint'); % button down detected
finalRect = rbbox; % return figure units
point2 = get(gca,'CurrentPoint'); % button up detected
point1 = point1(1,1:2); % extract x and y
point2 = point2(1,1:2);
p1 = min(point1,point2); % calculate locations
offset = abs(point1-point2); % and dimensions
x = [p1(1) p1(1)+offset(1) p1(1)+offset(1) p1(1) p1(1)];
y = [p1(2) p1(2) p1(2)+offset(2) p1(2)+offset(2) p1(2)];
hold on
axis manual
plot(x,y,'r','linewidth',5) % draw box around selected region
  2 Comments
Lin
Lin on 17 May 2011
Thank you very much
B_Richardson
B_Richardson on 7 Jul 2011
How can this be modified to allow multiple selections?

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks 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!