MATLAB: How to plot a graph with one series but different colors depending on another data

colorplot

How can I plot a graph with one series but different colors depending on another data ?

Best Answer

A line is a single color (limiting, I know, but true :( ) so to have different colors along the length of a line you'll have to break the line into segments where the color is to change.
A scatter plot, otoh, creates a marker for each point so each can have a different color. You might consider a single neutral-color line with the markers on it showing the color gradient as an expedient.
Related Question