How can I display Z coordinate of a 3D plot, on an Edit field (numeric) in app designer.

2 vues (au cours des 30 derniers jours)
How can I display Z coordinate of a 3D plot on edit field (numeric), when I click on a specific point on the plot, is there any way to do this on app designer?

Réponses (1)

Nivedita
Nivedita le 14 Sep 2023
Hi Abdulbagi,
I understand that you are display the Z coordinate of a 3D plot on a numeric edit field in MATLAB app designer.
You can do this in the following manner:
methods (Access = private)
function output_txt = myUpdateFcn(app,info)
% Get the datatip position
z = info.Position(3);
y = info.Position(2);
x = info.Position(1);
% Update the NumericEditField with the Z coordinate
app.EditField.Value = z;
% Create the datatip text
output_txt = {sprintf('X: %.3f', x), sprintf('Y: %.3f', y), sprintf('Z: %.3f', z)};
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];
z = [0 1 2 3 4 5 6 7 8 9];
plot3(app.UIAxes, x, y, z, 'o-', 'LineWidth', 2, 'MarkerSize', 8);
dcm = datacursormode(app.UIFigure);
dcm.Enable = 'on';
dcm.DisplayStyle = 'datatip';
dcm.UpdateFcn = @(src, event)myUpdateFcn(app, event);
end
end
In the “startup” function, a 3D 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, Y, and Z coordinates are extracted from the info.Position property. The Z coordinate is then assigned to the Value property of the NumericEditField component (app.EditField.Value = z;). The datatip text is created using “sprint” to format the X, Y, and Z coordinates with three decimal places.
For more information about “datacursormode”, you can refer to the following documentation link:
I hope this helps!
Regards,
Nivedita.

Catégories

En savoir plus sur Develop Apps Using App Designer 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!

Translated by