1
votes

Suppose I have a dataset which consists of three vectors which represent a trajectory in 3D. This temporal data can be plotted in Matlab with the following command: plot3(Data(:,1),Data(:,2),Data(:,3),'.r');

The output is a "cloud" of points: enter image description here

I would like to visualize the trajectory, so my question is: How do I modify the plot so that the color of the points represent the index (time) of the temporal data? Just to make my point a bit clearer, imagine a trajectory of points that change color "smoothly" from red to blue in a way that will enable me to visualize the trajectory.

1

1 Answers

1
votes

I can think of two answers:

use the surface function on a 3D line like this:

color=1:length(Data(:,1));

surface([Data(:,1);Data(:,1)],[Data(:,2);Data(:,2)][Data(:,3);Data(:,3)],[color ;color],...
    'facecol','no','edgecol','interp');

this is a very nice trick, but it plots a line.

If you want to plot points, you can define an RGB color and plot single points with hold on like this:

hold on

for i=1:length(Data(:,1)) 

    plot3(Data(i,1),Data(i,2),Data(i,3),'Color',[(i/100*255)/255 0/255 (255-(i/100*255))/255],'LineWidth',2)

end    

shg