I have a data set that looks like this
140400 70.7850 1
140401 70.7923 2
140402 70.7993 3
140403 70.8067 4
140404 70.8139 5
140405 70.8212 3
Where the first column corresponds to time (one second intervals between data points) and will be on the x axis, the second column corresponds with distance and will be on the y axis. The third column is a number (one through five) that is a qualification of the movement.
I want to make a plot that changes the color of the line between two points depending on what the number of the previous data point was. For example, I want the line to be red between the first and second data points because the qualification value was 1.
I've seen a lot of posts about making a sliding scale of colors depending on an intensity value, but I just want 5 colors: (red, orange, yellow, green, and blue) respectively.
I tried doing something like this:
plot(x,y,{'r','o','y','g','b'})
But with no luck.
Any ideas of how to approach this? Without looping if possible.
When the result figure of two variables plotted is a circle, will be necessary to add the time in z axes.
For example the figure of induction machine rotor velocity vs electric torque in one laboratory test is: 2d plot figure
In the last figure the direction of the time point plotting could be clockwise or counter clockwise. For the last reason will be added time in z axis.
Finally we can view the 3d form and detect that counterwise is the real direction of the time plotting is: 3d plot
You can also do it with a trick which works with Matlab version anterior to 2014b (as far back as 2009a at least).
However, is will never be as simple as you expected (unless you write a wrapper for one of the solution here you can forget about
plot(x,y,{'r','o','y','g','b'})
).The trick is to use a
surface
instead of aline
object. Surfaces benefit from theirCData
properties and a lot of useful features to exploit color maps and texture.Matlab
surf
does not handle 1D data, it needs a matrix as input so we are going to give it by just duplicating each coordinate set (for examplexx=[x,x]
).Don't worry though, the surface will stay as thin as a line, so the end result is not ugly.
will get you:
As an example of a more general case:
will give you a sine wave with the color associated to the
y
value:My desired effect was achieved below (simplified):
Do you have Matlab R2014b or higher?
Then you could use some undocumented features introduced by Yair Altman: