JA_CFs_trial_type_within_games_Stage2.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. function [final_design, game, real_trials_number, catch_trials_number] = JA_CFs_trial_type_within_games_Stage2(GD)
  2. % outputs a structure with the features of the trials for each game
  3. % number of standard games
  4. standard_games_number = length(find(~strcmp(GD.games_distribution_names, {'wash_out'})));
  5. % set number of real trials per game
  6. real_trials_number = 9;
  7. % sets the number of catch trials per game
  8. catch_trials_number = 2;
  9. % initialise real_trials and catch_trials variables with empty cells
  10. real_trials = repmat({[]},[1,real_trials_number]);
  11. catch_trials = repmat({[]},[1,catch_trials_number]);
  12. total_trial_number = length([real_trials, catch_trials]);
  13. % initialise game variable
  14. game = cell(1,total_trial_number);
  15. % cue colors
  16. colors = {'press_color', 'lift_color'};
  17. TMS = {' '};
  18. % how many possible combinations
  19. combinations = length(colors)*length(colors)*length(TMS);
  20. % the two target colors for each participants are balanced and already randomized
  21. [color_CF_list, color_SBJ_list, TMS_list] = ...
  22. BalanceFactors((real_trials_number*standard_games_number)/combinations, 1, colors,colors,TMS);
  23. colors_combinations = [color_CF_list, color_SBJ_list, TMS_list];
  24. colors_idx = linspace(0, real_trials_number*standard_games_number,standard_games_number+1);
  25. % similar for the catch trials except that for CF is always orange, while
  26. % for SBJ can be either red or yellow.
  27. catch_colors_CF = {'catch_color', 'catch_color'};
  28. catch_combinations = length(catch_colors_CF)*length(colors)*length(TMS);
  29. % make combination and randomize couples
  30. [catch_color_CF_list, catch_color_SBJ_list, catch_TMS_list] = ...
  31. BalanceFactors((catch_trials_number*standard_games_number)/catch_combinations, 0, catch_colors_CF,colors, TMS);
  32. catch_colors_combinations = [catch_color_CF_list, catch_color_SBJ_list, catch_TMS_list];
  33. catch_colors_idx = linspace(0, catch_trials_number*standard_games_number,standard_games_number+1);
  34. % for each game set trials features
  35. % randomization of the trials order is performed at the end of the for
  36. % cycle
  37. for x = 1:length(GD.games_distribution_names)
  38. if strcmp(GD.games_distribution_names(x), 'wash_out')
  39. [wash_out_final_design, washout_game] = JA_internal_fun_washout_game()
  40. game{x} = washout_game;
  41. else
  42. col{x} = colors_combinations(colors_idx(x-1)+1:colors_idx(x),:);
  43. catch_col{x} = catch_colors_combinations(catch_colors_idx(x-1)+1:catch_colors_idx(x),:);
  44. col_tot_tmp{x} = cat(1,col{x},catch_col{x});
  45. % which trial is slow and which is fast
  46. tmp_real = real_trials;
  47. tmp_real(1:GD.games_distribution(x)) = {'slow_tr'};
  48. tmp_real(GD.games_distribution(x)+1:end) = {'fast_tr'};
  49. % up to this point set catch trials as 'ok_catch'
  50. tmp_catch = repmat({'ok_catch'},[1,length(catch_trials)]);
  51. % is a game containing catch trial failure?
  52. if ismember(x, GD. CF_catch_failing_game)
  53. % set the first element ad failed_catch
  54. tmp_catch(1,1) = {'failed_catch'};
  55. end
  56. % put real and catch trials in a single vector
  57. tmp_total = [tmp_real tmp_catch];
  58. % randomizes real and catch trials within each game
  59. rand_idx = randperm(total_trial_number);
  60. game{x}.sequence = tmp_total(rand_idx);
  61. col_tot{x} = col_tot_tmp{x}(rand_idx,:);
  62. % add info to the game struct
  63. if strcmp(GD.games_distribution_names(x), 'slow')
  64. game{x}.slow_game = 'yes';
  65. end
  66. game{x}.slow_trials_quantity = GD.games_distribution(x);
  67. game{x}.slow_trials = find(strcmp(game{x}.sequence, 'slow_tr'));
  68. game{x}.fast_trials = find(strcmp(game{x}.sequence, 'fast_tr'));
  69. game{x}.ok_catch_trials = find(strcmp(game{x}.sequence, 'ok_catch'));
  70. game{x}.out_slow_trials = find(strcmp(game{x}.sequence, 'out_slow'));
  71. game{x}.out_fast_trials = find(strcmp(game{x}.sequence, 'out_fast'));
  72. game{x}.failed_catch_trials = find(strcmp(game{x}.sequence, 'failed_catch'));
  73. game{x}.colors_CF = col_tot{x}(:,1);
  74. game{x}.colors_SBJ = col_tot{x}(:,2);
  75. game{x}.TMS = col_tot{x}(:,3);
  76. game{x}.number = repmat(num2cell(x), [total_trial_number 1]);
  77. table_games{x} = table(game{x}.number, game{x}.sequence',game{x}.colors_CF,game{x}.colors_SBJ,game{x}.TMS);
  78. game{x}.table = table_games{x};
  79. game{x}.table.Properties.VariableNames = {'Games', 'Type', 'CF_colors', 'SBJ_colors', 'TMS'};
  80. end
  81. end %for
  82. final_design_tmp = cat(1,table_games{2:end});
  83. final_design = cat(1,washout_game.table, final_design_tmp);
  84. final_design.Properties.VariableNames = {'Games', 'Type', 'CF_colors', 'SBJ_colors', 'TMS'};
  85. %size(find(sum([strcmp(final_design{:,2},'yellow'), strcmp(final_design{:,3},'yellow'),strcmp(final_design{:,1},'fast_tr')],2) == 3))
  86. %test_final_design = final_design([find(strcmp(final_design{:,1},'slow_tr')); find(strcmp(final_design{:,1},'fast_tr'))],:);
  87. function [wash_out_final_design, washout_game] = JA_internal_fun_washout_game()
  88. %% create colors for washout
  89. % create dummy sequence of colors
  90. wash_out_sequence_colors_tmp = repmat(colors', [real_trials_number, 1]);
  91. %randomize dummy sequence of colors for SBJ
  92. wash_out_idx_SBJ = randperm(total_trial_number);
  93. %randomize dummy sequence of colors for SBJ (also catch are either red or yellow for SBJ)
  94. wash_out_idx_CF = randperm(total_trial_number);%randperm(length(wash_out_sequence_tmp));
  95. %keep only the first 11 which equals --> wash_out_sequence for SBJ is ok
  96. wash_out_catch_sequence_SBJ = wash_out_sequence_colors_tmp(wash_out_idx_SBJ(1:total_trial_number));
  97. %keep only the first 11 which equals --> wash_out_sequence for CF
  98. wash_out_catch_sequence_CF = wash_out_sequence_colors_tmp(wash_out_idx_CF(1:total_trial_number));
  99. %randomize dummy sequence of colors for catch_colors_CF
  100. wash_out_catch_idx_CF_tmp = randperm(total_trial_number);
  101. % select the first two (number of catch trials)
  102. wash_out_catch_idx_CF = wash_out_catch_idx_CF_tmp(1:length(catch_colors_CF));
  103. %catch trials which are orange
  104. wash_out_catch_sequence_CF(wash_out_catch_idx_CF) = catch_colors_CF;
  105. %% create slow/fast
  106. wash_out_slow_fast_tmp = repmat({'slow_tr'; 'fast_tr'}, [real_trials_number, 1]);
  107. %randomize dummy sequence of slow/fast
  108. wash_out_slow_fast_idx = randperm(total_trial_number);
  109. wash_out_slow_fast = wash_out_slow_fast_tmp(wash_out_slow_fast_idx);
  110. wash_out_slow_fast(wash_out_catch_idx_CF) = {'ok_catch'};
  111. %%
  112. wash_out_TMS = repmat(TMS, [total_trial_number 1]);
  113. %check
  114. wash_out_final_design = [wash_out_slow_fast wash_out_catch_sequence_CF wash_out_catch_sequence_SBJ wash_out_TMS];
  115. washout_game.sequence = wash_out_final_design(:,1);
  116. washout_game.slow_trials_quantity = GD.games_distribution(1);
  117. washout_game.slow_game = {''} ;
  118. washout_game.slow_trials = find(strcmp(washout_game.sequence, 'slow_tr'))';
  119. washout_game.fast_trials = find(strcmp(washout_game.sequence, 'fast_tr'))';
  120. washout_game.ok_catch_trials = find(strcmp(washout_game.sequence, 'ok_catch'));
  121. washout_game.out_slow_trials = find(strcmp(washout_game.sequence, 'out_slow'));
  122. washout_game.out_fast_trials = find(strcmp(washout_game.sequence, 'out_fast'));
  123. washout_game.failed_catch_trials = find(strcmp(washout_game.sequence, 'failed_catch'));
  124. washout_game.colors_CF = wash_out_final_design(:,2);
  125. washout_game.colors_SBJ = wash_out_final_design(:,3);
  126. washout_game.TMS = wash_out_final_design(:,4);
  127. washout_game.number = repmat(num2cell(1), [total_trial_number 1]);
  128. table_washout_game = table(washout_game.number, washout_game.sequence,washout_game.colors_CF,washout_game.colors_SBJ,washout_game.TMS);
  129. washout_game.table = table_washout_game;
  130. end
  131. end