Why does the Gaussian fit function become highly inaccurate after 24 iterations in a for loop?

2 views (last 30 days)
I am attempting to fit 24 spectra corresponding with 24 files in a directory with MatLab's Gaussian fit function, 'gauss6'. These spectra are processed in a for loop that repeats for each file in the directory. The outputs of this loop are the optimized peak locations, intensities, etc. However, when MatLab attempts to perform the fit function for the 24th spectrum, the final peak's position (sixth) is completely incorrect, while the other five peaks are just as correct as the previous 23 spectra. This doesn't occur for directories of 23 files or less, but always happens to the final peak of the final spectrum if the number of spectra being fit is greater than 24.
Things I have tried:
  • Given 25 spectra, the last peak of the 25th is incorrect. It's always the final peak of the last file/spectrum if the files are greater than 24.
  • Isolating the 24th spectrum by itself yields a correct fitting.
  • It seems like the R^2 gets worse slowly as the number of spectra being fit increases.
  3 Comments
Brian Oistad
Brian Oistad on 22 May 2020
Thank you for your prompt response, Rik. I'm relatively new to MatLab, so in regards to making a MWE, I can recreate the for loop containing the fitting functions, R^2, etc., but can't think of a way to simulate the data set. As stated above, the data are 24 1024x2 doubles, each containing six "peaks" representing spectra that are relatively well fit by Gaussian functions (with the exception of the error that I'm seeing).
Do you have any suggestions to simulate the aforementioned circumstances without any dependencies?

Sign in to comment.

Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!