Generate catch trial numbers in blocks of a certain length

2 vues (au cours des 30 derniers jours)
Bram Adrichem
Bram Adrichem le 18 Juin 2019
Modifié(e) : Bram Adrichem le 18 Juin 2019
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

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by