StimulusDomain_ND.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. function [ stimSize, sortedFieldNameInds, fieldNames, stimParamsFlat ] = StimulusDomain_ND( stimParams, fieldNamesToUse )
  2. %UNTITLED8 Summary of this function goes here
  3. % Detailed explanation goes here
  4. if HasBlankEpoch( stimParams )
  5. stimParams = stimParams(2 : end);
  6. end
  7. stimParamsFlat = FlattenStruct( stimParams );
  8. fieldNames = fieldnames( stimParamsFlat );
  9. %% make intensity field
  10. if any( ismember( fieldNames, 'lum' ) ) && any( ismember( fieldNames, 'contrast' ) )
  11. for epochInd = 1 : numel( stimParamsFlat )
  12. stimParamsFlat(epochInd).intensity = stimParamsFlat(epochInd).lum * stimParamsFlat(epochInd).contrast * 2;
  13. end
  14. stimParamsFlat = orderfields( stimParamsFlat );
  15. fieldNames = fieldnames( stimParamsFlat );
  16. end
  17. %% make temporal frequency field
  18. if any( ismember( fieldNames, 'spacing' ) ) && any( ismember( fieldNames, 'stimtrans_mean' ) )
  19. for epochInd = 1 : numel( stimParamsFlat )
  20. stimParamsFlat(epochInd).temporalFrequency = stimParamsFlat(epochInd).stimtrans_mean / stimParamsFlat(epochInd).spacing;
  21. end
  22. stimParamsFlat = orderfields( stimParamsFlat );
  23. fieldNames = fieldnames( stimParamsFlat );
  24. end
  25. %% clean up fields that do not vary. not strictly necessary
  26. fieldInd = 1;
  27. while fieldInd <= numel( fieldNames )
  28. if numel( unique( [stimParamsFlat.(fieldNames{fieldInd})] ) ) == 1
  29. stimParamsFlat = rmfield( stimParamsFlat, fieldNames{fieldInd} );
  30. fieldNames = fieldnames( stimParamsFlat );
  31. else
  32. fieldInd = fieldInd + 1;
  33. end
  34. end
  35. %% select fields using fieldNamesToUse
  36. if ~exist( 'fieldNamesToUse', 'var' ) || isempty( fieldNamesToUse )
  37. if all( [stimParams.stimtype] == 11 )
  38. %fieldNamesToUse = {'intensity', 'tau'}; % default stimulus parameters to use
  39. end
  40. if all( [stimParams.stimtype] == 46 )
  41. fieldNamesToUse = {'intensity', 'spacing', 'stimrot_mean', 'temporalFrequency'}; % default stimulus parameters to use
  42. end
  43. if all( [stimParams.stimtype] == 50 )
  44. fieldNamesToUse = {'intensity', 'spacing', 'stimrot_mean', 'stimtrans_mean'}; % default stimulus parameters to use
  45. end
  46. if all( [stimParams.stimtype] == 57 )
  47. fieldNamesToUse = {'stimtrans_amp'}; % default stimulus parameters to use
  48. end
  49. end
  50. fieldInd = 1;
  51. while fieldInd <= numel( fieldNames )
  52. if all( ~ismember( fieldNamesToUse, fieldNames{fieldInd} ) )
  53. stimParamsFlat = rmfield( stimParamsFlat, fieldNames{fieldInd} );
  54. stimParamsFlat = orderfields( stimParamsFlat );
  55. fieldNames = fieldnames( stimParamsFlat );
  56. else
  57. fieldInd = fieldInd + 1;
  58. end
  59. end
  60. for fieldInd = 1 : numel( fieldNames )
  61. axisPeriod(fieldInd) = find( diff( [stimParamsFlat.(fieldNames{fieldInd})] ) ~= 0, 1 );
  62. end
  63. [~, sortedFieldNameInds] = sort( axisPeriod );
  64. for fieldInd = 1 : numel( fieldNames )
  65. stimSize(fieldInd) = numel( unique( [stimParamsFlat.(fieldNames{sortedFieldNameInds(fieldInd)})] ) );
  66. end
  67. end