- The demo script below takes 6 sample location points and number of trials for each location is 5.
- The script makes use of a dictionary where the keys represent the location which is a string constructed using x & y coordinates.
- The values corresponding to keys are the count of total trials for that location.
Randomize location by trial & reshuffle location if condition not met
1 次查看(过去 30 天)
显示 更早的评论
I have the following code that allows me to present a stimulus at a location randomly selected from a list of X,Y coordinates 10 times before changing to another randomly selected location. I would like it to 1. present the stimulus at each location 10 times but randomize the location every trial (e.g. Trial 1: X1,Y1; Trial 2: X3, Y3; Trail 3: X7,Y7; Trial 4: X1,Y1; etc. trial count at X1,Y1 = 2 out of 10, all others = 1 out of 10) & 2. reshuffle the tested location into the pool if a condition is not met prior to presentation.
I am thinking this may require me to create a list of all potential trials and have the program randomly pull from that list. Any thoughts or advice would be appreciated.
for k = 1 : numel(X_vector)
n_trials = 10;
if strcmp(Testing_Mode,'random')
idx=randperm(length(X_vector),42);
x = X_vector(idx(k));
y = Y_vector(idx(k));
end
end
0 个评论
回答(1 个)
Divyanshu
2023-5-17
Hi HumbleCoder,
Few pointers to consider for better understanding of the sample script:
Here is the sample script which you can refer to:
x_vec = [0 2 3 7 8 1]';
y_vec = [1 4 5 2 9 6]';
locations = ["01" "24" "35" "72" "89" "16"];
values = [0 0 0 0 0 0];
d = dictionary(locations,values);
for k = 1 : length(x_vec)
n_trials = 5;
idx=randperm(length(x_vec),6);
x = x_vec(idx(k));
y = y_vec(idx(k));
temp = string(x) + string(y);
if(d(temp) >= 5)
%here put the logic to reshuffle the current location if condition
%is not met.
else
d(temp) = d(temp)+1;
end
end
Please go through the following documentation for more details on dictionary:
2 个评论
Dyuman Joshi
2023-6-1
You can simply use logical indexing, paired with strcmp in case of the above example posted by Divyanshu.
Also replace
idx=randperm(length(x_vec),6)
with
idx = randi(length(x_vec))
and directly use idx.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!