Gaussian fit function question
显示 更早的评论
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
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 个)
类别
在 帮助中心 和 File 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!