Change axis color on parts of the mesh

11 views (last 30 days)
I would like this plot to have 2 colors on the same surface, meaning: blue between the x values of 1 and 2 and then between 9 and 10 and red on the rest of it.
Here's the code:
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surf(X,Y,Z)

Accepted Answer

Voss
Voss on 18 Sep 2022
Edited: Voss on 18 Sep 2022
Here's one way:
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
C = 1 + (X <= 2 | X >= 9);
surf(X,Y,Z,C)
colormap([1 0 0; 0 0 1]);

More Answers (0)

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by