Generate catch trial numbers in blocks of a certain length

2 次查看(过去 30 天)
Hi,
I am doing an experiment and I want to insert a certain amount of catch trials randomly during my experiment. It is important that these catch trials are more or less equally spaced troughout the experiment. Right now I solved it in the following way:
%% A function to randomly create the intances of the catch trials
% By Bram van Adrichem
clear all
close all
clc
NrTrials = 150;
NrEC = 15;
NrCatchTrials = 15;
NrData = NrTrials/NrEC;
BlockStart = 2;
RandomNumber = CatchTrialMoment(NrTrials,NrCatchTrials,BlockStart);
function RandomNumber = CatchTrialMoment(NrTrials,NrCatchTrials,BlockStart)
BlockLength = NrTrials/NrCatchTrials;
for ii = 1:NrCatchTrials
RandomNumber(ii) = (BlockLength*(ii-1)) + datasample(BlockStart:BlockLength,1);
end
end
I think this code works, but my two question are:
Is there already a matlab function that can do this?
Are there more people struggling with this kind of problem, because then I could upload it to the file- exchange

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by