3D plotting in MATLAB
2 次查看（过去 30 天）
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); %
% My probable Solution for Second Part
plot3(xt, yt, zt, 'LineWidth',1);
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.
Nithin Kumar 2023-8-28
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');
To plot a ‘1cm’ long line into both directions along the sensor’s orientation, Kindly refer to the following code:
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');
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.