Datacursor: How to avoid returning to the workspace

1 回表示 (過去 30 日間)
Michael Lherbette
Michael Lherbette 2016 年 2 月 11 日
編集済み: Walter Roberson 2016 年 2 月 11 日
Hello,
I am writing a GUI in which the user need to select 3 points on an axes. The user will need to left click on the plot then press a key on the keyboard to store the position of the cursor.
Here is my code:
dcm_obj = datacursormode(gcf);
for i = 1 : 3
k = 0;
while k == 0
set(dcm_obj,'DisplayStyle','window',...
'SnapToDataVertex','off','Enable','on')
k = waitforbuttonpress;
end
c_info = getCursorInfo(dcm_obj);
point(i,:) = c_info.Position;
end
datacursormode off
It works but as soon as the user press enter, matlab goes back to the workspace. Thus the GUI is not displayed after this operation and the user need to click on the GUI window to restore it. Not friendly at all.
Any idea to avoid that ?
Thank you,
ML
  1 件のコメント
Matthew
Matthew 2016 年 2 月 11 日
Two things to consider:
One is that matlab has a builtin function to do what it sounds like you're doing: ginput.
Secondly, if ginput doesn't meet your needs, then a pretty easy way to do what you're trying to do is simply add a figure handle call to the end of your callback - something like figure(myGuiHandle)
I suppose you could also access the java object and set the GUI so that its always on top while this operation is being performed.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 2 月 11 日
That is really a misuse of datacursormode. You should use ginput() for that, or perhaps impoly() or rbbox() or similar.
In my opinion, you should not use datacursormode() for anything other than displaying the cursor position (in whatever coordinate system makes sense.)
  2 件のコメント
Michael Lherbette
Michael Lherbette 2016 年 2 月 11 日
I need 3D position of the cursor ... not only X and Y.
Walter Roberson
Walter Roberson 2016 年 2 月 11 日
編集済み: Walter Roberson 2016 年 2 月 11 日
Note: if you use that, watch out for the HitTest and (R2014b or newer) PickableParts properties of children objects.

サインインしてコメントする。

その他の回答 (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