I have two sets of 3D points over time and I want to include a line between the each of the coresponding two points at each time value. For example:
A_3Dpts= [-0.91, 0.53, 0.32; -.88, .51, .3; -.84, .43, .16]
B_3Dpts= [-0.909, 0.51, 0.321; -.8, .59, .34; -.8, .4, .1]
I've tried using plot3() but only seem to be able to connect the points from the same 3D XYZ points instead of the two seperate groups.
I'll include an image of what I'm hoping to accomplish.

 채택된 답변

Star Strider
Star Strider 2023년 11월 9일

1 개 추천

I assume the rows are the (x,y,z) coordinates,
If so, try this —
A_3Dpts= [-0.91, 0.53, 0.32; -.88, .51, .3; -.84, .43, .16]
A_3Dpts = 3×3
-0.9100 0.5300 0.3200 -0.8800 0.5100 0.3000 -0.8400 0.4300 0.1600
B_3Dpts= [-0.909, 0.51, 0.321; -.8, .59, .34; -.8, .4, .1]
B_3Dpts = 3×3
-0.9090 0.5100 0.3210 -0.8000 0.5900 0.3400 -0.8000 0.4000 0.1000
figure
hold on
for k = 1:size(A_3Dpts,1)
plot3([A_3Dpts(k,1);B_3Dpts(k,1)], [A_3Dpts(k,2);B_3Dpts(k,2)], [A_3Dpts(k,3);B_3Dpts(k,3)], '-k')
scatter3(A_3Dpts(k,1), A_3Dpts(k,2), A_3Dpts(k,3), 50, 'r', 'filled')
scatter3(B_3Dpts(k,1), B_3Dpts(k,2), B_3Dpts(k,3),50, 'g', 'filled')
end
hold off
grid on
view(-30,30)
If the columns are, then switch the subscripts, from (k,1) to (1,k) and so for the others.
.

댓글 수: 2

Robert
Robert 2023년 11월 9일
Thank you!! this is exactly what I need.
Star Strider
Star Strider 2023년 11월 10일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2023년 11월 9일

댓글:

2023년 11월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by