fitDifferenceOfGaussiansFromNeuronStimTables.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. function flyFits = fitDifferenceOfGaussiansFromNeuronStimTables(StimTableNeuronStim)
  2. tuningMethod = 'extreme';
  3. flyFits = {};
  4. for neuronTypeInd = 1: size(StimTableNeuronStim, 1)
  5. for stimInd = 2: size(StimTableNeuronStim, 2)
  6. TempTable = StimTableNeuronStim{neuronTypeInd, stimInd};
  7. for flyInd = 1: size(TempTable, 1)
  8. tuningInd = find(strcmp(TempTable.nonParamTuning{1}.tuningMethods, tuningMethod));
  9. tuningCurve = squeeze(TempTable.nonParamTuning{flyInd}.tc{tuningInd});
  10. if stimInd == 3 || stimInd == 5
  11. tuningCurve = tuningCurve(:, 3: end - 2);
  12. end
  13. if stimInd > 3
  14. gaussianSign = -1;
  15. else
  16. gaussianSign = 1;
  17. end
  18. % Still need to crop extremes for consistency with normal
  19. % fitting.
  20. xArray = 1: size(tuningCurve, 2);
  21. fitStruct(size(tuningCurve, 1), 1).fit = [];
  22. fitStruct(size(tuningCurve, 1), 1).gof = [];
  23. fitStruct(size(tuningCurve, 1), 1).info = [];
  24. for kCell = 1: size(tuningCurve, 1)
  25. [fitStruct(kCell).fit, ...
  26. fitStruct(kCell).gof.rsquare] = fitDifferenceOfGaussianConstraint(...
  27. xArray, ...
  28. tuningCurve(kCell, :), ...
  29. gaussianSign);
  30. figure;
  31. scatter(xArray, tuningCurve(kCell, :), 'filled');
  32. hold on;
  33. plot(xArray, differenceOfGaussians1D(fitStruct(kCell).fit, xArray));
  34. pause(0.01)
  35. end
  36. flyFits{neuronTypeInd, stimInd - 1, flyInd} = fitStruct;
  37. clear fitStruct;
  38. close all;
  39. end
  40. end
  41. end
  42. end