Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
Fabian
Posts:
22
Registered:
8/4/08
|
|
Re: Error bars in Matlab
Posted:
Aug 25, 2009 11:34 PM
|
|
"david szotten" <szotten@hotmail.com> wrote in message <fucptp$icn$1@fred.mathworks.com>... > Hi, > > a bit annoying to do, since the ends are actually part of > the plot itself. think the code below does the trick (may > submit at some point) > > > removeErrorBarEnds.m : > ------------- > function removeErrorBarEnds(hErrBar) > %removeErrorBarEnds > % removeErrorBarEnds(hErrBar) removes the lines > above/below errorbars > % generated by the matlab function hErrBar = errorbar() > % > % Example: > % x = 1:10; > % y = sin(x); > % e = std(y)*ones(size(x)); > % h = errorbar(x,y,e) > % oldAx = axis; > % removeErrorBarEnds(h) > % axis(oldAx) > > % david szotten > > %use length of xdata to find the right handle > %there may be an easier way to do this > dataLen = length( get(hErrBar, 'xdata') ); > > %objects to try, one of this is the errorbars > candidateList = findall(hErrBar); > > for candidate = candidateList(:)' > candLen = length( get(candidate, 'xdata') ); > > %found it > if candLen == 9 * dataLen > xOrg = get(candidate, 'xdata'); > yOrg = get(candidate, 'ydata'); > > %we only want the first 3 out or every 9 > valuesToExtract = find( kron( ones > (1,dataLen), [ones(1,3) zeros(1,6)]) ); > xNew = xOrg(valuesToExtract); > yNew = yOrg(valuesToExtract); > > set(candidate, 'xdata', xNew); > set(candidate, 'ydata', yNew); > end > end > > end > --------------------- > > > regards, > david > > > peppergrower <mjjohnson.geo@yahoo.com> wrote in message > <2924739.1208583860933.JavaMail.jakarta@nitrogen.mathforum. > org>... > > I'm trying to change the way error bars are displayed in > Matlab. Currently I'm using the errorbar command. It > works great, except for one thing: I don't want the small > horizontal lines at the top and bottom of the error bars. > I have a lot of data points on this plot, and it looks > really messy having all those extra horizontal lines. Is > there any way to turn off these, or is there possibly a > different command that will allow me to simulate error > bars without having the end markers? > > > > Thanks, > > peppergrower > Thanks David works like a star, one question, is there a way to only remove some errorbars? preferrably based upon their length? I am plotting my data in a way that for differences < 0 I only display the upper and for differences > 0 I only display the lower. So I fill arrays for ULower and UUpper for the errorbar(....) function according to the Y value and set the value to 0 if I don't want the bar. I then use your above function to remove the error tees which are still plotted even if bar length = 0, I'd like to only remove the errorbar tee for those errorbars of zero length. thanks loads
|
|
|
|