필터 지우기
필터 지우기

Draw lines between two given sets of points

조회 수: 4 (최근 30일)
Ahmed Hossam
Ahmed Hossam 2017년 9월 24일
댓글: Ahmed Hossam 2017년 9월 24일
I have two sets of points in 3D. These look for example like:
S1 = {(x1,y1,z1),(x2,y2,z2),...,(xn,yn,zn)}
S2 = {(x1',y1',z1'),(x2',y2',z2'),...,(xn',yn',zn')}
So both sets have the same number of points and I would like to connect them with lines like:
(x1,y1,z1) ---- (x1',y1',z1')
(x2,y2,z2) ---- (x2',y2',z2')
.
.
.
(xn,yn,zn) ---- (xn',yn',zn')
What would be the best way to achieve that at once? I could do that with a for-loop which will plot a line between each two points, but I am asking, if there's a way I could organise the data so that all lines can be plotted at the same time?...
Thanks very much for your help in advance!
Best Regards,
Ahmed Hossam

채택된 답변

Jan
Jan 2017년 9월 24일
편집: Jan 2017년 9월 24일
% Create some test data:
S1 = cell(1, 5);
for k = 1:5, S1{k} = rand(1, 3); end
S2 = cell(1, 5);
for k = 1:5, S2{k} = rand(1, 3); end
M1 = cat(1, S1{:}).';
M2 = cat(1, S2{:}).';
plot3([M1(1, :); M2(1, :)], [M1(2, :); M2(2, :)], [M1(3, :); M2(3, :)]);
Or equivalent:
M1 = cat(3, S1{:});
M2 = cat(3, S2{:});
M = permute(cat(1, M1, M2), [1, 3, 2]);
plot3(M(:, :, 1), M(:, :, 2), M(:, :, 3))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by