Plot bei steigendem Werten grün und bei fallenden Werten rot (Different coulored plot: increasing and decreasing)

3 views (last 30 days)
Guten Tag!
Ich möchte die Werte von einem Vektor grafisch darstellen. Mein Vektor ist unten im Code.
Ist es möglich, die Verbindungen, die von einer höheren zu einer niedrigeren Zahl gehen, rot zu färben und die Verbindungen von einer niedrigeren Zahl zu einer höheren grün zu färben? ( Also von 50 zu 49 rot färben, 49 zu 37 rot, 37 zu 65 grün, ...) Wenn ja, bitte ich euch/Sie um Hilfe. Vielen Dank im Vorhinein!
Hello!
I would like to graphically display the values in a vector. My vector is at the bottom.
Is it possible to color the connections going from a higher to a lower number red and the connections going from a lower number to a higher number green? (I mean from 50 to 49 red , 49 to 37 red, 37 to 65 green, ...If so, I am asking you politely for help. Thanks in advance!
v=[50 49 37 65 46 80 75 30 46 28 73 64]
plot(v)

Accepted Answer

Srivardhan Gadila
Srivardhan Gadila on 28 Nov 2020
Write a for loop iterating over the values of the array v, inside it check if previous element is less than or greater than the current element using if, elseif, else. Based on it assign the color green or red respectively by making use of colors in LineSpec of the plot function to plot the line formed by those two values and then using the hold command to retain the plot and move to next elements.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!