3D line plot between coordinates

조회 수: 3 (최근 30일)
proczell
proczell 2018년 1월 23일
답변: proczell 2018년 1월 23일
I am trying to make a function that draws lines between given coordinates in a MAT file. As an example, the MAT file can look as following. Where the second and third column are the x coordinates for the start and end of the point, the 4th and 5th for y and 6th and 7th for z.
The function nearly works as intended, and draws the three lines i specified. However, it adds one lines from (0,-6,24) to (18,-6,0). Anyone have an idea of how to make the function only draw the number of lines specified from the MAT file?
[1] [0] [ 0] [-6] [-6] [ 0] [ 24]
[1] [0] [ 18] [-6] [-6] [ 0] [ 0]
[1] [0] [14.5000] [-6] [-6] [24] [2.5000]
n = size(A.save_lines);
for i = 1:n(1)
X_start(i,1) = A.save_lines{i,2};
X_end(i,1) = A.save_lines{i,3};
Y_start(i,1) = A.save_lines{i,4};
Y_end(i,1) = A.save_lines{i,5};
Z_start(i,1) = A.save_lines{i,6};
Z_end(i,1) = A.save_lines{i,7};
end
X = [X_start , X_end]
Y = [Y_start , Y_end]
Z = [Z_start , Z_end]
X = reshape(X.',1,[])
Y = reshape(Y.',1,[])
Z = reshape(Z.',1,[])
line(X,Y,Z)

채택된 답변

proczell
proczell 2018년 1월 23일
Solved by adding the following code
for j = 1:length(X)
plot3(X(j,1:2),Y(j,1:2),Z(j,1:2),'b')
end
instead of the reshape process. Posted it here in case anyone needed it for any reason.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by