getRFsAlignedWithFit.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function [offX, offY, onX, onY] = getRFsAlignedWithFit(StimTableCell, rSqThresh, respIndThresh, varargin)
  2. if nargin > 3
  3. alignAll = varargin{1};
  4. if nargin > 4
  5. alignOrientation = varargin{2};
  6. else
  7. alignOrientation = true;
  8. end
  9. else
  10. alignAll = false;
  11. alignOrientation = true;
  12. end
  13. [tcArrayCell, responseIndArrayCell, rSquareArrayCell, fitParamsCell, ...
  14. flyIndsCell, tcExtCellArray, tcArgExtCellArray] = getStimArraysForSameRois(StimTableCell);
  15. % Align to fit
  16. posCell = cellfun(@(x) arrayfun(@(y) y.b1, x, 'uni', 0), fitParamsCell, 'uni', 1);
  17. widthCell = cellfun(@(x) arrayfun(@(y) 2 * (2 * sqrt(log(2))) * y.c1, x, 'uni', 0), ...
  18. fitParamsCell, 'uni', 1); % The 2 factor is because of bar separation.
  19. lagsCell = cellfun(@(x, y) round(x - size(y, 2) / 2), posCell, tcArrayCell, 'uni', 0);
  20. barRFs = cellfun(@(x, y) alignRFsToAbsMax(x, 0, y'), tcArrayCell, lagsCell, 'uni', 0);
  21. validIndsCell = cellfun(@(x, y) x(:) > rSqThresh & y(:) > respIndThresh, ...
  22. rSquareArrayCell, responseIndArrayCell, 'uni', 0)';
  23. %% Blank epoch was already deleted, now delete vertical bars on edges of screen.
  24. barRFs{2}(:, end-1: end) = [];
  25. barRFs{4}(:, end-1: end) = [];
  26. barRFs{2}(:, 1: 2) = [];
  27. barRFs{4}(:, 1: 2) = [];
  28. %%
  29. if alignAll
  30. validAll = validIndsCell{1} & validIndsCell{2} & ...
  31. validIndsCell{3} & validIndsCell{4};
  32. offX = barRFs{1}(validAll, :);
  33. offY = barRFs{2}(validAll, :);
  34. onX = barRFs{3}(validAll, :);
  35. onY = barRFs{4}(validAll, :);
  36. elseif alignOrientation
  37. offX = barRFs{1}(validIndsCell{1}&validIndsCell{2}, :);
  38. offY = barRFs{2}(validIndsCell{2}&validIndsCell{1}, :);
  39. onX = barRFs{3}(validIndsCell{3}&validIndsCell{4}, :);
  40. onY = barRFs{4}(validIndsCell{4}&validIndsCell{3}, :);
  41. else
  42. offX = barRFs{1}(validIndsCell{1}, :);
  43. offY = barRFs{2}(validIndsCell{2}, :);
  44. onX = barRFs{3}(validIndsCell{3}, :);
  45. onY = barRFs{4}(validIndsCell{4}, :);
  46. end
  47. end