plotting trajectory data in matlab

I have trajectory information in 3 dimensions in matlab. These are of a gesture someone is making. When I connect the points in matlab by using plot3, I can see the trajectory nicely. However, the trajectory is a line in the plot, but I don't know in which direction the gesture has been made as the time is not visualized. Is it possible to visualize this in a 3d plot (where the dimensions are x, y and z)? For example, the colour at the start is bright red and the colour at the end is black.

Thanks for your help,

Héctor

Upvotes: 2

Views: 4977

Answers (1)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38032

You need the comet3 plot (if you don't mind animations).

If you do mind animations, and you're looking for a static figure, I'd use a quiver.

Example:

% value of the parameter in the parametric equation
t = 0:0.5:2*pi;

% modified coordinate axes
u = [1 0 0].';
v = [0 2 0].';

% coordinates of the ellipse
Ell  = bsxfun(@plus, bsxfun(@times, u, cos(t)), bsxfun(@times, v, sin(t)));

% difference vectors between all data points will be used as "velocities"
dEll = diff(Ell, 1,2);

% Quiver the ellipse
quiver3(...
    Ell(1,1:end-1), Ell(2,1:end-1), Ell(3,1:end-1), ...
    dEll(1,:), dEll(2,:), dEll(3,:), ...
    2,  'r')  % = scale, LineSpec

axis tight equal

Result:

enter image description here

Upvotes: 4

Related Questions