Gaussian fit function question

조회 수: 10 (최근 30일)
Emily Stadnicki
Emily Stadnicki 2020년 10월 13일
댓글: Asvin Kumar 2021년 3월 15일
I am trying to fit my data to a gaussian curve after cleaning it up for only values that are significant with a p less than 0.05. I have loaded the data and gotten the ANOVA values for all 40 experiments and now must create a gaussian curve but my coade keeps giving me an error at the line when i define the fit. I have attached what I have so far. Any input is helpful! Thank you.
function [outcomes,a,b,c,d] = fit_arm_nerve_practice('folder')
subdirs = dir('folder');
outcomes = [];
a = []; b = []; c = []; d = [];
for i=1:length(subdirs),
if subdirs(i).isdir&~strcmp(subdirs(i).name,'.')&~strcmp(subdirs(i).name,'..'),
filename = ['folder' filesep subdirs(i).name filesep 'mouse_arm_data.txt'];
if exist(filename),
disp(['Analyzing file ' filename '.']);
data = load(filename,'-ascii');
locations = data(1,:);
rawdata = data(2:end,:);
outcomes(i) = anova1([rawdata;],locations,'off');
if outcomes<0.05,
% write your own gaussfit function, where x and y
% are your data points
fo = fitoptions('Method','NonLinearLeastSquares','StartPoint',[1 1]);
gauss = fittype('a+b*exp(-((x-c).^2)/((2*d^2)))','options',fo);
gauss = setoptions(gauss,fo);
[gof] = fit(locations',rawdata',gauss);
[a,b,c,d] = gaussfit(x,y);
a(end+1) = a_;
b(end+1) = b_;
c(end+1) = c_;
d(end+1) = d_;
else,
a= NaN;
b= NaN;
c= NaN;
d= NaN;
end;
end;
end;
end;
  댓글 수: 1
Asvin Kumar
Asvin Kumar 2021년 3월 15일
What's the error that you're seeing? Error stack would be helpful for anyone trying to answer this question.
Also, this code is hard to work with because we don't have the folders or files that this file is looking for. If possible, attach a MWE which reproduces your issue so the community can help you out.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Analysis of Variance and Covariance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by