MATLAB: Preparing a list of numbers based on certain rules and conditions

Dear All,
I need to generate a list of 100 trials for my experiment. Each trial is a row with 5 columns consisting of the numbers 1,2,3,4 and 5. Eg: Trial 1 = 5 3 2 1 4 Trial 2 = 5 4 2 3 1 Trial 3 = 4 2 3 5 1 The conditions and rules are as follows:
1) The number 5 is the target number
2) None of the numbers from 1 to 5 should repeat itself within a trial except in catch trials.
3) Valid trials = In 60 % of the trials the target number should occur in the first column
4) Invalid trials = 20 % of the trials the target number should occur in the remaining columns (2nd, 3rd, 4th and 5th columns). The individual probability of target number occurring in each of these 4 columns should be nearly equal. Invalid trails cannot occur consecutively and should be preceded by either a catch trial or valid trial with equal probability.
5) Catch trials = In the remaining 20 % of the trials none of the columns should contain the target number. Any one non-target number from 1 to 4 can be repeated with equal probability of each of those 4 numbers to be repeated within the 20 trials
6) There should be a minimum of 3 consecutive valid trials before a catch or invalid trial.
As I am just a beginner, any help in this regard is much appreciated. Thanks in anticipation.
Regards, Imran

Best Answer

I would split this problem into two parts. The first part would be to create a cell array trialType (100 x 1) which indicates the type of trial (valid, invalid, or catch) that satisfies all the requirements on the trials (i.e., 60%, 20%, 20%, no consecutive invalid trials, and starting with 3 valid trials). Then once you know the trial type, make the row of 5 numbers for each trial.
Related Question