How to get point value in app designer plots?

조회 수: 48 (최근 30일)
Davide Mastrodicasa
Davide Mastrodicasa 2020년 1월 27일
댓글: Davide Mastrodicasa 2020년 1월 31일
Hello everyone.
Is there a way to get a point value from a plot using the mouse cursor in appdesigner? This is my code in a script file and it works pretty good but I can't translate it into the AppDesigner world.
% Other code lines
if app.qq==1
i=1;
dcm_obj = datacursormode;
set(dcm_obj,'DisplayStyle','window','SnapToDataVertex','on','Enable','on')
waitforbuttonpress
c_info{i} = getCursorInfo(dcm_obj); %#ok
Freq_line=c_info{1,i}.Position(1);
idx=find(app.H.f==Freq_line);
app.qq=2;
q=1; %#ok
end
% Other code lines
I gave a look online but it seems that both datacursormode and waitforbuttonpress don't works in AppDesigner. I didn't find any answer yet and I hope someone could help me.
Thank you in advance for your reply.

채택된 답변

Adam Danz
Adam Danz 2020년 1월 27일
편집: Adam Danz 2020년 1월 28일
Provide the app's figure handle in your call to datacursormode.
The window DisplayStyle is not supported in UIfigures.
The default value to SnapToDataVertex is on so you don't need to include that.
dcm_obj = datacursormode(app.MyAppUIFigure);
dcm_obj.Enable = 'on';
I'm not sure what cursorInfo is in your code.
update
In 2019b, after executing the lines above if the mouse hovers over a data point and creates a data tip, the following warning appears. Apparently this functionality hasn't been rolled out yet.
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Error using matlab.ui.Figure/set
Functionality not supported with figures created with the uifigure function. For more information, see Graphics Support in App Designer.
Error in setptr (line 386)
An alternative would be to use the data tips by hovering the mouse over a data point. This code below waits for a data tip to appear and then extracts its coordinates.
tth = findall(app.UIAxes,'Type','hggroup'); % find any pre-existing data tips
delete(tth) % remove them
tth = [];
while isempty(tth)
tth = findall(app.UIAxes,'Type','hggroup');
pause(0.1) % important, without it Matlab crashes
end
disp(tth.Position)
  댓글 수: 3
Adam Danz
Adam Danz 2020년 1월 28일
편집: Adam Danz 2020년 1월 28일
At the top of the page you shared, it states, "Use this function only with GUIDE, or with apps created with the figure function." That warning indicates that the function isn't suppored by appdesigner. waitfor() may be useful. You can set it up so it waits for a property of an object to change and that property could be related to the datacursor. I haven't played around with it but that's an idea to try out.
Update: see my updated answer for a problem with datacursormode in uiaxes.
Davide Mastrodicasa
Davide Mastrodicasa 2020년 1월 31일
Ok perfect. I solved also the other problem of the waitforbuttonpress using waitfor(obj,propname) and adding another button.
Thank you very much for your help Adam

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by