How do I put error bars on a best fit curve?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Mike Garrity
2016년 3월 28일
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)
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Errorbars에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!