필터 지우기
필터 지우기

How to draw 3D XYZ plot with a matrix?

조회 수: 3 (최근 30일)
ruik zhang
ruik zhang 2018년 8월 4일
답변: ruik zhang 2018년 8월 5일
Hello, I have a 3D matrix (x, y ,z) such as:
38 70 0;
42 70 2;
42 72 4;
45 71 -2;
43 75 3
I want to draw a 3D XYZ plot as shown in the fig attached,each two neighbour points are connected with an arrow line. The color of the line between each two points is related to the index of the end point. Could you please help me with this? It is appreciated!
Ruik

채택된 답변

jonas
jonas 2018년 8월 5일
편집: jonas 2018년 8월 5일
I stitched this together using quiver3. Possibly a bit buggy.
%%Start point coordinates
A=[38 70 0;
42 70 2;
42 72 4;
45 71 -2;
43 75 3]
%%Length of arrows
B=[diff(A);0 0 0]
%%Plot
figure;hold on
cm=colormap(jet(length(A)-1));
colorbar(gca,'ticks',1:length(A))
caxis([1 length(A)])
for i=1:length(A)-1
s=sqrt(sum(B(i,:).^2)); %Equally sized arrow heads
%s=.3 %Uncomment for scaled arrow heads
h(i)=quiver3(A(i,1),A(i,2),A(i,3),B(i,1),B(i,2),B(i,3),1,'maxheadsize',1.5/s)
h(i).Color=cm(i,:);
end
box on
grid on
view(3)
set(h,'linewidth',2)

추가 답변 (1개)

ruik zhang
ruik zhang 2018년 8월 5일
Hi Jonas, it seems work well. Thank you. Ruik

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by