Coordinates related to rbbox in GUI

3 次查看(过去 30 天)
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

采纳的回答

Matt Fig
Matt Fig 2011-5-17
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 个评论
B_Richardson
B_Richardson 2011-7-7
How can this be modified to allow multiple selections?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by