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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by