Change axis color on parts of the mesh

2 vues (au cours des 30 derniers jours)
Alexandra Roxana
Alexandra Roxana le 18 Sep 2022
Commenté : Voss le 19 Sep 2022
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)

Réponse acceptée

Voss
Voss le 18 Sep 2022
Modifié(e) : Voss le 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]);
  2 commentaires
Alexandra Roxana
Alexandra Roxana le 18 Sep 2022
Great and easy! Thanks a lot!
Voss
Voss le 19 Sep 2022
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by