Say I have a vector of independent variable values
v =[ 1 2 2 1 1 .5 1 2 .5 .5 1]
and a vector of response variables
u = [ 5 22 20 4 8 .2 5 12 0 .5 6]
I want to plot u
vs. v
with errorbars, the method needs to work for 100s of possible values for the independent variable. The problem isn't in plotting the error bars, it's in how can I create a vector pair [mean(u(find(v==0.5)), mean(u(find(v==1)), mean(u(find(v==2))]
. Is there a standard automated way of doing this other than sorting v
, then picking out the values of sorted v
and finding the index of v
where v
matches those values? This seems very inefficient.