Effacer les filtres
Effacer les filtres

Why does my gaussian fit give an error?

3 vues (au cours des 30 derniers jours)
JJH
JJH le 5 Déc 2018
Commenté : Image Analyst le 5 Déc 2018
I have a code that loops through a set of .csv files and imports the data stored in them as Wavelength and Intensity and correctly returns the wavelength and intensity as arrays. I then want to fit the data to a Gaussian. Some of the files have all of the values of the intensity being zero, so I have put a check in for this. The code currently is
for kk = 2:DataPointsSpec+1 % loop through each file - DataPointsSpec defined previously
SpectrumData = PeakFit([FolderName '\' Direc(kk).name]); % only relevant thing here is csvread for each file
clear Wavelength % this doesn't seem to help
clear Intensity
Wavelength = SpectrumData(2:end-1,1); %ignore first and last point in data (not relevant)
Intensity = SpectrumData(2:end-1,2);
peak = findpeaks(Intensity,'NPeaks',1,'MinPeakProminence',1*10^-3,'MinPeakDistance',20); % determines whether or not a peak is present
if isempty(peak)
peakposarray(kk) = nan % if there is no peak, print NaN in place of the peak wavelength
else
gaussianfit = fit(Wavelength,Intensity,'gauss2') % if there is a peak, fit it to a Gaussian
end
end
However, when I try to do a Gaussian fit on the non-zero data, I get an error saying 'Index in position 1 is invalid. Array indices must be positive integers or logical values.' I'm not sure why there is a problem, as all I want to do is to fit some data that is in the form [x,y].
  1 commentaire
Image Analyst
Image Analyst le 5 Déc 2018
Provide the data, full code, and FULL error message (including line of code and line number) so that people can reproduce and fix the problem.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by