How can I use datacursormode in app designer?

function RunButton_2Pushed(app, event)
FU = scatteredInterpolant(app.resp(:,1),app.resp(:,2),app.resp(:,3),'natural','none');
FV = scatteredInterpolant(app.resp(:,1),app.resp(:,2),app.resp(:,4),'natural','none');
x1 = 0:app.spacing:app.sx;
y1 = 0:app.spacing:app.sy;
[xx,yy] = meshgrid(x1,y1);
uu = FU(xx,yy);
vv = FV(xx,yy);
usm = WSmooth(uu,app.smoothing);
vsm = WSmooth(vv,app.smoothing);
svec = [floor((app.sy)/app.spacing+1) ...
floor((app.sx)/app.spacing+1)];
upoly1 = usm;vpoly1 = vsm;
xx1 = xx;yy1 = yy;
[~,xh] = contourf(app.UIAxes3,xx,yy,usm,32);
colorrange = [min(usm(:)),max(usm(:))];
colormap(app.UIAxes3,'jet');
colorbar(app.UIAxes3,'eastoutside');
set(xh,'linecolor','none');
axis(app.UIAxes3,'equal');axis(app.UIAxes3,'tight');
disableDefaultInteractivity(app.UIAxes3);
datacursomode(app.UIAxes3,'on')
title(app.UIAxes3,{'Displacement-X [mm]';['Max(up) :',num2str(max(usm(:)),'%10.4f')...
' Max(lo) :', num2str(min(usm(:)),'%10.4f')];['Mean :',num2str(mean(usm(:)),'%10.4f')]});
end
I've tried to run my app, but I always had a problem in datacursormode line. It said that I use the wrong handler and I knew it, but I need to show my contour data and I need to be able to extract or read data in my contour. Tbh I don't have this problem if I do the same command but in matlab command not in app designer. Please help me because I need to make an app :). Thx

6 Comments

@Aldo Baits which version of MATLAB are you using? Also, please copy and paste the full error message to your question.
Please note that at here says
datacursormode(ax,option) sets the data cursor mode for the specified axes. For example, to enable data cursor mode for the axes ax, use datacursormode(ax,'on'). Use this syntax with apps created in App Designer and using the uifigure function. (since R2023a)
I use MATLAB R2022b, this is my error message
Error using datacursormode
Invalid figure handle
Error in app1/RunButton_2Pushed (line 149)
datacursormode(app.UIAxes3,'on');
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
>>
It seems like you are not giving right input parameters (figure) to datacursomode so can you try by giving an UIFigure as first parameter, Like
datacursomode(app.UIFigure, 'on')
@Sandeep Mishra I know that I need to use UIfigure, but at the same time I need to extract data from my contour which run on app.Uiaxis, what bother me is I can use datacursor mode in matlab base command but I cant use it when I use app desginer
I have MATLAB R2023a. I have a matlab app with different UIAxes. I would like to assign different custom data cursor behavior for each UIAxes. However, when I try to use:
dcm1 = datacursormode(app.UIAxes1, 'on');
I get matlab error saying: Invalid figure handle. I don't understand what's the reason behind that specifically that it's supposed to be a valid new feature:
"datacursormode(ax,option) sets the data cursor mode for the specified axes. For example, to enable data cursor mode for the axes ax, use datacursormode(ax,'on'). Use this syntax with apps created in App Designer and using the uifigure function. (since R2023a)"
Xiaoyu
Xiaoyu on 1 Aug 2024
Moved: Matt J on 1 Aug 2024
Hi :
Have you solved this problem? I'm having the same issue.

Sign in to comment.

Answers (1)

Matt J
Matt J on 4 Jul 2023
Edited: Matt J on 4 Jul 2023
Yes, it's an unfortunate deficiency, and one of the main reasons I'm still using GUIDE. One workaround is to make an additional app button that lets you insert a text arrow (using annotation for example).

Categories

Products

Release

R2022b

Asked:

on 3 Jul 2023

Moved:

on 1 Aug 2024

Community Treasure Hunt

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

Start Hunting!