Change axis color on parts of the mesh

6 Ansichten (letzte 30 Tage)
Alexandra Roxana
Alexandra Roxana am 18 Sep. 2022
Kommentiert: Voss am 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)

Akzeptierte Antwort

Voss
Voss am 18 Sep. 2022
Bearbeitet: Voss am 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 Kommentare
Alexandra Roxana
Alexandra Roxana am 18 Sep. 2022
Great and easy! Thanks a lot!
Voss
Voss am 19 Sep. 2022
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by