0
votes

In https://www.amcharts.com/demos/line-different-colors-ups-downs/,

enter image description here

it describes plotting different colors for up and downs. How can I do the same for matlab? I attach an example

plot([1 2 3 4 5 6 7 8 9 10], [5 5 7 5 2 5 5 8 9 2])

which involves no change as well. I want to have yellow for ups and blue for downs, and red for no change.enter image description here

1

1 Answers

1
votes

In the figure two different colors are chosen. You may follow something like this:

x = [1 2 3 4 5 6 7 8 9 10] ;
y = [5 5 7 5 2 5 5 8 9 2] ;


figure
hold on
for i = 1:length(x)-1
   m = (y(i)-y(i+1))/(x(i)-x(i+1)) ;
   if sign(m)==0
        plot(x(i:i+1),y(i:i+1),'r') ;
   elseif sign(m)==-1
        plot(x(i:i+1),y(i:i+1),'b') ;
   elseif sign(m)==1
        plot(x(i:i+1),y(i:i+1),'y') ;
   end
end