Gaussian fit function question

8 visualizaciones (últimos 30 días)
Emily Stadnicki
Emily Stadnicki el 13 de Oct. de 2020
Comentada: Asvin Kumar el 15 de Mzo. de 2021
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 comentario
Asvin Kumar
Asvin Kumar el 15 de Mzo. de 2021
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Analysis of Variance and Covariance en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by