- In the “startup” function, a line plot is generated using random data. Then the “datacursormode” object (“dcm”) is enabled and set to display datatips. The “UpdateFcn” property is set to the “myUpdateFcn” function, which will be called when the datatip is updated.
- Inside “myUpdateFcn”,the x and y coordinates are extracted from the “info.Position”property. The datatiptext is created using “sprint”to format the x and y coordinates with three decimal places.
difference between axe toolbar in app designer and in standalone application
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
In app designer (R2020b), the default axe toolbar menu is composed of 'export', 'brush','zoomin','zoomout',and 'restoreview' buttons. 'datacursor' is not present but when no button are selected, the datacursor is automatically active and works correctly.
When I export this app as standalone application, only 'export', 'zoomin','zoomout',and 'restoreview' are now available and datacursor function is not active.
Is there a solution to fix this problem?
Thanks for your help.
Philippe
0 commentaires
Réponses (2)
Nivedita
le 14 Sep 2023
Modifié(e) : Nivedita
le 14 Sep 2023
Hi Philippe,
I understand that you are unable to get the "datacursor" function in the standalone application.
To fix this issue, you can create custom datatips for your plot. Here is an example how you can do so:
methods (Access = private)
function output_txt = myUpdateFcn(app,info)
% Get the datatip position
y = info.Position(2);
x = info.Position(1);
% Create the datatip text
output_txt = {sprintf('X: %.3f', x), sprintf('Y: %.3f', y)};
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
x = [0 1 2 3 4 5 6 7 8 9];
y = [0 1 2 3 4 5 6 7 8 9];
plot(app.UIAxes, x, y);
dcm = datacursormode(app.UIFigure);
dcm.Enable = 'on';
dcm.DisplayStyle = 'datatip';
dcm.UpdateFcn = @(src, event)myUpdateFcn(app, event);
end
end
For more information about “datacursormode”, you can refer to the following documentation link:
I hope this helps!
Regards,
Nivedita.
0 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!