orderGratingFlashes.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. function [ prs ] = orderGratingFlashes( nimages, npulses, maxrepeats, seed )
  2. %FINDNEWORDER Recover the order of cta,ctb from the new SubUnitFlash stimulus
  3. % The new stimulus only has radial components and more
  4. % parameters such as range of radial search, number of angles,
  5. % number of contrasts, etc. It also uses a different shuffling which
  6. % might give a different ordering than the one Michael has used
  7. % before.
  8. %
  9. % [ cta, ctb, totalflashes, prs ] = findNewOrder( stimdesc, npulses, maxrepeats, seed )
  10. %
  11. % Input:
  12. % stimdesc: struct containing description of stimulus
  13. % (mincontrast, maxcontrast, ncontrasts, nangles)
  14. % npulses: number of pulses recorded from the experiment
  15. % maxrepeats: only analyze until the maxrepeats-th repeat
  16. % (use 'inf' for analyzing all the repeats)
  17. % seed: seed for ran1 (should be the same as in the experiment)
  18. %
  19. % Output:
  20. % cta: contrast at subtiles A, ctb: contrast at subtiles B
  21. % totalflashes: total number of flashes in one repeat
  22. % prs: order in which the contrasts are used
  23. %
  24. prs = zeros(nimages * maxrepeats, 1);
  25. for ii = 1:maxrepeats
  26. [order, seed] = shuffleOrder(nimages, seed);
  27. prs( (ii-1)*(nimages) + (1:nimages) ) = order;
  28. end
  29. prs = prs(1:npulses);
  30. end
  31. function [order, seed] = shuffleOrder(nelem, seed)
  32. % Fisher-Yates shuffle (initializes the vector in a random order)
  33. order = ones(nelem, 1);
  34. for ii = 1:nelem
  35. [jj, seed] = ran1(seed);
  36. jj = floor(1 + (ii-1)*jj);
  37. order(ii) = order(jj);
  38. order(jj) = ii;
  39. end
  40. end