Summary

The simple (very simple) function EBplotyy is used with plotyy to make one or more errorbar plots on one figure with y-axes on the left and right sides.

Example

Examples of how to use the code:

Example 1: Plotting two errorbar plots with the same x-axis and different y-axis

M1=randn(100,10);
M2=randn(100,10);
x=linspace(1,10,10);
[a,h1,h2]=plotyy(x,M1,x,M2,'EBplotyy','EBplotyy');
set(get(a(1),'Ylabel'),'String','Data 1')
set(get(a(2),'Ylabel'),'String','Data 1')
set(get(a(2),'Xlabel'),'String','Points')
title('Two Errorbar Plots')

Example 2: Plotting one errorbar plot and a non-errorbar plot on the same x-axis with different y axis

M1=randn(100,10);
x=linspace(1,10,10);
y=2*x;
[a,h1,h2]=plotyy(x,M1,x,y,'EBplotyy','plot')
set(get(a(1),'YLabel'),'String','Errorbar Plot')
set(get(a(2),'YLabel'),'String','Some Other Plot')
title('Errorbar Plot and some other Random Plot')
set(get(a(1),'XLabel'),'String','Points')

Code

function h=EBplotyy(x,y)
%INPUT:
%x-independent variable (often Time)
%y-dependent variable
%OUTPUT:
%h-handle of the errorbar graphics object
%
%Save this code in an m-file named EBplotyy.m

s=nanstd(y);
h=errorbar(x,nanmedian(y),nanstd(y));  %NOTE: You might want to change nanmedian to nanmean, nanstd to standard error, etc depending on what you want to plot