How do I duplicate a row in a randomly ordered array?
Afficher commentaires plus anciens
I am creating a moving square-wave grating to act as a visual stimulus that loops through an array of randomly ordered spatial frequency (SF) and temporal frequency (TF) in two opposite directions. I currently have the stimulus such that every time one row of the array is presented, the next one is of a random other combination of frequencies and another direction (which could be the same or the opposite). The change I want to make is that I want each combination of frequencies to be played in both directions sequentially instead of at some other random point in the array. So for example, instead of a stimulus with TF = 1, SF = 1, and Direction = 180 followed by TF = 3, SF = 3, Direction = 180. I want the stimulus to play the TF=1, SF=1, Direction = 180, followed by TF=1, SF=1, Direction=360, then onto the next random frequency combination.
Here is my code for the stim_grid, which is the randomly ordered array of frequency and direction:
%Temporal frequency vector temp_freq = [0.031,0.125,0.5,2,8,16]; %Spatial frequency vector spat_freq = [0.000657,0.001336,0.002651,0.0053,0.0106,0.0212];%calculated using trigonometry and the width of the %stimulus computer in cm spatemp_array = combvec(temp_freq,spat_freq);
%%Make array column 1 = TF, column 2 = SF, column 3 = direction stim_grid = [ repmat(spatemp_array',2,1),[repmat(stim_dir(1),length(spatemp_array'),1); repmat(stim_dir(2),length(spatemp_array'),1)] ]; %Make first pair of TF, SF, and direction stim_grid = [stim_grid(randperm(length(stim_grid)),1:3)];
Réponses (1)
Jos (10584)
le 14 Sep 2017
A suggestion:
[SF, TF, D] = ndgrid([1 2 3], [10 20 30 40], [180 360]) % combinations three spatial and four temporal frequencies, and TWO directions
M = [SF(:) TF(:) D(:)] % ordered list
N = size(M,1)/2
ridx = randperm(N)
ridx = [ridx ; ridx+N]
Mfinal = M(ridx,:)
1 commentaire
Graham Smyth
le 14 Sep 2017
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!