How can I display a line in 3D with a colour gradient?
Let’s say I have a set of 10 tridimensional points, represented as a 3 by 10 matrix, such as these points generated just for the sake of illustration:
n = 10;
x = linspace(1, 2, n);
y = cos(x);
z = y.^2;
points = [x’ y’ z’]
I can display them as a line in 3D:
plot3(points(:,1,:), points(:,2,:), points(:,3,:));
My question is: how can I apply a color gradient to this line, so we can see in what direction does the line evolve (relative to the order of the point in the points matrix)?
I tried several methods, without success so far:
Calling plot3 with the c parameter (as suggested by an answer on the Internet): the c keyword is not recognised.
Calling colormap with a custom made map: no graph is displayed at all, even though no error is thrown.
cmap = [linspace(0, 1, n)’ zeros(n, 1) zeros(n, 1)];
colormap(cmap);Let’s say I have a set of 10 tridimensional points, represented as a 3 by 10 matrix, such as these points generated just for the sake of illustration:
n = 10;
x = linspace(1, 2, n);
y = cos(x);
z = y.^2;
points = [x’ y’ z’]
I can display them as a line in 3D:
plot3(points(:,1,:), points(:,2,:), points(:,3,:));
My question is: how can I apply a color gradient to this line, so we can see in what direction does the line evolve (relative to the order of the point in the points matrix)?
I tried several methods, without success so far:
Calling plot3 with the c parameter (as suggested by an answer on the Internet): the c keyword is not recognised.
Calling colormap with a custom made map: no graph is displayed at all, even though no error is thrown.
cmap = [linspace(0, 1, n)’ zeros(n, 1) zeros(n, 1)];
colormap(cmap); Let’s say I have a set of 10 tridimensional points, represented as a 3 by 10 matrix, such as these points generated just for the sake of illustration:
n = 10;
x = linspace(1, 2, n);
y = cos(x);
z = y.^2;
points = [x’ y’ z’]
I can display them as a line in 3D:
plot3(points(:,1,:), points(:,2,:), points(:,3,:));
My question is: how can I apply a color gradient to this line, so we can see in what direction does the line evolve (relative to the order of the point in the points matrix)?
I tried several methods, without success so far:
Calling plot3 with the c parameter (as suggested by an answer on the Internet): the c keyword is not recognised.
Calling colormap with a custom made map: no graph is displayed at all, even though no error is thrown.
cmap = [linspace(0, 1, n)’ zeros(n, 1) zeros(n, 1)];
colormap(cmap); plot3, colormap MATLAB Answers — New Questions