How do I put error bars on a best fit curve?

5 views (last 30 days)
CAM
CAM on 28 Mar 2016
Commented: Mike Garrity on 28 Mar 2016
I have a series of data which I wanted to find the Gaussian of (I'll admit that it isn't a great fit, but that's the data I'm working with). The data came directly from a sensor measuring count rate at a specific bias voltage (so there is likely some noise).
What I'm doing in the program is calling the excel file (which contains the data from my sensor), then I am trying to put the error bars on the graph as well. When I run the code, I get the error bars separated from the actual graph itself! Can someone help me to get this code correct? It seems like it should be fairly simple, but I'm missing something. I'm attaching the excel file with the data points I pull!
clc
clear all
[v,T,vT]=xlsread('seventypointtwoZero.xlsx'); % calls the excel file
% 'xlsx' for excel 2007 and higher
%v: Double
%T and vT : cell
%use v containing numbers
t=v(:,1);
y=v(:,2);
f = fit(t,y,'gauss1')%Gaussian fit
yfit=feval(f,t)
plot(f,t,y)%plots the points and the Gaussian fit
hold on
errorbar(yfit, t)%plots the error bars
hold off
title('Bias of 70.2 Gaussian')
xlabel('Charge (ADC channels)') % x-axis label
ylabel('Counts') % y-axis label
Thanks!
  1 Comment
Mike Garrity
Mike Garrity on 28 Mar 2016
I don't understand the intent of this line:
errorbar(yfit, t)%plots the error bars
The syntax for errorbar is some variant of this:
errorbar(X,Y,E) or errorbar(Y,E) plots Y with error bars [Y-E Y+E].
But isn't YFIT your Y coordinate, and T your X coordinate?
I would have expected something more like this:
errorbar(t,yfit,y-yfit)

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!