- 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 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Nivedita
2023-9-14
编辑:Nivedita
2023-9-14
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!