Coordinates related to rbbox in GUI

조회 수: 3 (최근 30일)
Lin
Lin 2011년 5월 17일
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
Lin
Lin 2011년 5월 17일
Thank you very much
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