Ploting same y axis with two colors
Show older comments
Assuming there is matrix 10x2, which is called HW. First collumn values will be the X axis. Second collumn is [1,4,5,7,2,24,8,9,18,11] and will be in Y axis. In the plot, higher y values than average will be in different color than lower y values. I wrote this code which does not work due to numbers does not match and I am unable to find a proper plot function. I cannot use programming (such as: if statements). By the way X also randomly distributed.
I need them in one line. Such as from 1 to 2 (first 5 element) line is red than to 6th element, 24, blue and goes like this (r,b,r,b)
HWT = find(HW(:,1)>=mean(HW(:,1)))
HWS = find(HW(:,1)<=mean(HW(:,1)))
plot(HW(:,1),HW(HWT,2),"Color","r",HW(HWS,2),"Color","b")
Is there any plot function to solve this.
Thank you for your help.
Accepted Answer
More Answers (1)
Walter Roberson
on 24 Oct 2023
0 votes
See https://www.mathworks.com/matlabcentral/fileexchange/19476-colored-line-or-scatter-plot or https://www.mathworks.com/matlabcentral/fileexchange/26692-color_line or https://www.mathworks.com/matlabcentral/fileexchange/23566-3d-colored-line-plot or https://www.mathworks.com/matlabcentral/fileexchange/30423-conditionally-colored-line-plot?s_tid=prof_contriblnk
1 Comment
Gökberk Kaya
on 26 Oct 2023
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
