Use this function to plot several time series aligned beneath each other with shaded blocks highlighting important sections.
It sounds like you want multiple lines on a single plot instead of several subplots. There are many variations like this and I don't know how to deal with them without adding loads of parameters or creating several new functions.
I think you can work around it as follows. Run shadedTimeSeries(x,y1,indicator) first. This will give you a single plot with the coloured bars. Then 'hold all'. Then plot(x,y2); plot(x,y3)... This will overlay your other plots on top. Unfortunately, the height of the bars is based on the values of y1, so you have to make sure that y1 goes above and below the other variables.
Feel free to tweak the script for your own purposes. I think you just need to call the internal plot_partial() function with multiple columns in ydata.
thanks a lot for this script and the examples. It's totally what I needed.
But how could I manage to put shade in a plot which contains several different lines of data.
Example: One contains the data:
-->now I'd like to use your shadedTimeSeries function within this single plot
Is this possible?
I uploaded a new version which allows you run this function with only one column of data to populate your own subplots (instead of creating a new figure). Not sure if that's what Kuo-Hsien was requesting. See the examples in the documentation to see how this works.
Thanks for the feedback. Not sure what you mean about subplots.
If you just want to display the part of the legend that shows the shaded colour then you can add legend('Interesting bit'); after this function. I feel that anything more sophisticated will be difficult to generalise and may be quite specific to your particular problem. It might be easier if you tweak the function yourself.
Hi Carl, this is a useful function. How to show the box for subplots and legend? thx.
Thanks for the suggestion Shlomi. I've submitted an update but I also added some extra sanity checks to ensure sizes are consistent.
if the indicator is a row vector the function doesn't work properly. I added the simple command of indicator = indicator(:); in my code. You should add it too
Slight improvement to parameter consistency checks.
Accept different indicators to shade each subplot differently.
Detect inconsistent data lengths.
Fixed bug that occurred when X was a row vector.
Allow data in rows or columns. Extra sanity checks on data lengths.