Borrar filtros
Borrar filtros

3D plotting in MATLAB

6 visualizaciones (últimos 30 días)
Amit Chakraborty
Amit Chakraborty el 9 de Jun. de 2022
Respondida: Nithin Kumar el 28 de Ag. de 2023
I have 3 sensors wich are situated in X Y Z axes.
From those sensors , I have a data which is a 3D matrix. The question is :
a) Need to plot the position data(3D matrix) as circles using plot3
b) Also Need to plot a 1cm long line into both directions along the sensor's orientation.
% My probable Solution for First Part
sensor_data = randi([1 10],16,16,16); %
grid on
% My probable Solution for Second Part
plot3(xt, yt, zt, 'LineWidth',1);
grid on
I am confused with the second portion specifically : "Need to plot a 1cm long line into both directions" .
Are my solutions correct ? or what might be the probable solution for second part.

Respuestas (1)

Nithin Kumar
Nithin Kumar el 28 de Ag. de 2023
Hi Amit,
I understand that you are facing an issue while plotting 3D data.
For plotting the position data (3D matrix) as circles using plot 3, the provided code in the question does not define the variables 'xt', 'yt' and 'zt'.
To generate the desired output, kindly consider modifying the code as shown below:
sensor_data = randi([1 10], 16, 16, 16);
xt = 1:16;
yt = 1:16;
zt = 1:16;
subplot(1, 2, 1);
plot3(xt, yt, zt, 'o');
grid on;
To plot a ‘1cmlong line into both directions along the sensor’s orientation, Kindly refer to the following code:
hold on;
X_data = sensor_data(:, :, 1);
Y_data = sensor_data(:, :, 2);
Z_data = sensor_data(:, :, 3);
scatter3(X_data(:), Y_data(:), Z_data(:), 'o');
quiver3(X_data(:), Y_data(:), Z_data(:), X(:), Y(:), Z(:), 0.01, 'r');
title('Sensor Data');
hold off;
Kindly adjust the above code by providing the actual sensor orientation vectors ‘x’, ‘y’ and ‘z’ as per your requirement.
The “quiver3” function in the above code takes the sensor positions as the starting points and the orientation vectors (X, Y, and Z) as the directions of the lines. The next argument '0.01' specifies the length of the lines as ‘1cm’. The 'r' argument sets the color of the lines to red.
For more information regarding the “quiver3” function, kindly refer to the following documentation:
I hope this answer helps you.


Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.



Community Treasure Hunt

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

Start Hunting!

Translated by