How can I display a line in 3D with a colour gradient?
4 views (last 30 days)
Show older comments
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);
0 Comments
Accepted Answer
Voss
on 10 May 2024
n = 10;
x = linspace(1, 2, n);
y = cos(x);
z = y.^2;
points = [x' y' z']
surf(points(:,[1 1]),points(:,[2 2]),points(:,[3 3]),[1:n; 1:n].', ...
'FaceColor','none','EdgeColor','interp','LineWidth',2)
0 Comments
More Answers (0)
See Also
Categories
Find more on Red in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!