3D plotting in MATLAB
조회 수: 3 (최근 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); %
figure;
subplot(1,2,1);
plot3(xt,yt,zt,'o');
grid on
% My probable Solution for Second Part
subplot(1,2,2);
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.
댓글 수: 0
답변 (1개)
Nithin Kumar
2023년 8월 28일
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;
figure;
subplot(1, 2, 1);
plot3(xt, yt, zt, 'o');
grid on;
To plot a ‘1cm’ long line into both directions along the sensor’s orientation, Kindly refer to the following code:
figure;
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');
xlabel('X');
ylabel('Y');
zlabel('Z');
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!