How to plot a 2d matrix on a 3d graph?

조회 수: 3 (최근 30일)
Lucas Carvalho
Lucas Carvalho 2015년 3월 20일
댓글: Lucas Carvalho 2015년 3월 20일
Hi guys, I want to plot in 3d a matrix whose columns represent points in the space:
A = [x0 x1 x2 .... xn; y0 y1 y2 .... yn; z0 z1 z2 .... zn]
So the first point is [x0;y0;z0], the second one [x1;y1;z1], until the last n-th point. My intention is to create a trajectory between these points. I have already tried surf, mesh and other 3d plots, but none of them are doing it.
Thank you!

채택된 답변

Konstantinos Sofos
Konstantinos Sofos 2015년 3월 20일
Hi,
So the problem is that you do not want to plot a matrix but the information contained in 3 vectors (which are the columns of a matrix) in 3D. Have you tried griddata?
As an example
X=rand(1,30);
Y=rand(1,30);
Z=rand(1,30);
[XI YI ZI] = griddata(X,Y,Z,linspace(0,1),linspace(0,1)');
surf(XI,YI,ZI)
Regards
  댓글 수: 1
Lucas Carvalho
Lucas Carvalho 2015년 3월 20일
Thank you for the suggestion Konstantinos, but I've figured out another way. My example is below with the graph:
W = @(e,omega,t,a,b,c)[e*cos(omega*t) - sin(omega*t).*(a - b*t);
e*sin(omega*t) + cos(omega*t).*(a - b*t);
c+4*t];
e = 50;
omega = 10;
t = 1:0.01:10;
a = 20;
b = 5;
c = 2;
W_f = W(e,omega,t,a,b,c);
for i=1:(numel(W_f(1,:))-1)
p1 = W_f(:,i)';
p2 = W_f(:,i+1)';
pts = [p1;p2];
grid;
plot3(pts(:,1),pts(:,2),pts(:,3))
hold all
i=i+1;
end

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

추가 답변 (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