dataProcessValid_Exp3.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. %Name: dataProcessValid.m
  2. %
  3. %Autor: Xuelian Zang
  4. %Description: process valid data for selected subjects with stable
  5. %performance
  6. %
  7. %Date: 22/09/2015
  8. function dataOut = dataProcessValid(dataIn,Exp)
  9. try
  10. %plot black and white together
  11. trainMeanSub_RT1 = grpstats(dataIn.train.valid(dataIn.train.valid.RT1 > 0, :), {'New1','NE','NSub'},{'mean','numel'}, 'datavars',{'RT1'});
  12. if ~isempty(trainMeanSub_RT1)
  13. trainMeanAllCombine_RT1 = grpstats(trainMeanSub_RT1, {'New1','NE'},{'mean','sem','numel'}, 'datavars',{'mean_RT1'});
  14. %o1E1 o1E2 o1E3 o1E4 o1E5 o0E1 o0E2 o0E3 o0E4 o0E5
  15. subNumLeft = length(unique(trainMeanSub_RT1.NSub) );
  16. dataOut.forSpss.trainRTLeftCombine = dataset({reshape(trainMeanSub_RT1.mean_RT1, subNumLeft, []),...
  17. 'o1E1', 'o1E2', 'o1E3', 'o1E4', 'o1E5' , 'o0E1', 'o0E2', 'o0E3', 'o0E4', 'o0E5'} );
  18. end
  19. trainMeanSub_RT2 = grpstats(dataIn.train.valid(dataIn.train.valid.RT2 > 0, :), {'New1','NE','NSub'},{'mean','numel'}, 'datavars',{'RT2'});
  20. if ~isempty(trainMeanSub_RT2)
  21. trainMeanAllCombine_RT2 = grpstats(trainMeanSub_RT2, {'New1','NE'},{'mean','sem','numel'}, 'datavars',{'mean_RT2'});
  22. subNumRight = length(unique(trainMeanSub_RT2.NSub) );
  23. dataOut.forSpss.trainRTRightCombine = dataset({reshape(trainMeanSub_RT2.mean_RT2, subNumRight, []),...
  24. 'o1E1', 'o1E2', 'o1E3', 'o1E4', 'o1E5' , 'o0E1', 'o0E2', 'o0E3', 'o0E4', 'o0E5'} );
  25. end
  26. %% test session, all color instruction reversed
  27. testMeanSub_RT1 = grpstats(dataIn.test.valid(dataIn.test.valid.RT1 > 0, :), {'New1','NE','NSub'},{'mean','numel'}, 'datavars',{'RT1'});
  28. if ~isempty(testMeanSub_RT1)
  29. testMeanAllCombine_RT1 = grpstats(testMeanSub_RT1, {'New1','NE'},{'mean','sem','numel'}, 'datavars',{'mean_RT1'});
  30. dataOut.forSpss.testRTLeft = dataset({reshape(testMeanSub_RT1.mean_RT1, subNumLeft, []),'old','new'});
  31. end
  32. testMeanSub_RT2 = grpstats(dataIn.test.valid(dataIn.test.valid.RT2 > 0, :), {'New1','NE','NSub'},{'mean','numel'}, 'datavars',{'RT2'});
  33. if ~isempty(testMeanSub_RT2)
  34. testMeanAllCombine_RT2 = grpstats(testMeanSub_RT2, {'New1','NE'},{'mean','sem','numel'}, 'datavars',{'mean_RT2'});
  35. dataOut.forSpss.testRTRight = dataset({reshape(testMeanSub_RT2.mean_RT2, subNumRight, []),'old','new'});
  36. end
  37. if ~isempty(testMeanSub_RT1) && ~isempty(testMeanSub_RT2)
  38. %combine the left and right participants together
  39. dataCombine = dataset( {[ trainMeanSub_RT1.New1 trainMeanSub_RT1.NE trainMeanSub_RT1.NSub trainMeanSub_RT1.mean_RT1; ...
  40. trainMeanSub_RT2.New1 trainMeanSub_RT2.NE trainMeanSub_RT2.NSub trainMeanSub_RT2.mean_RT2; ...
  41. testMeanSub_RT1.New1 testMeanSub_RT1.NE testMeanSub_RT1.NSub testMeanSub_RT1.mean_RT1; ...
  42. testMeanSub_RT2.New1 testMeanSub_RT2.NE testMeanSub_RT2.NSub testMeanSub_RT2.mean_RT2;], ...
  43. 'New', 'NE', 'NSub','meanRT'});
  44. tmp = grpstats(dataCombine, {'New','NE','NSub'},{'mean','numel'}, 'datavars',{'meanRT'});
  45. dataOut.forSpss.RTAllCombine = dataset({reshape(tmp.mean_meanRT, Exp.subNum, []),...
  46. 'o1E1', 'o1E2', 'o1E3', 'o1E4', 'o1E5' ,'o1E6','o0E1', 'o0E2', 'o0E3', 'o0E4', 'o0E5', 'o0E6'} );
  47. elseif ~isempty(testMeanSub_RT1)
  48. %combine the left and right participants together
  49. dataCombine = dataset( {[ trainMeanSub_RT1.New1 trainMeanSub_RT1.NE trainMeanSub_RT1.NSub trainMeanSub_RT1.mean_RT1; ...
  50. testMeanSub_RT1.New1 testMeanSub_RT1.NE testMeanSub_RT1.NSub testMeanSub_RT1.mean_RT1;], ...
  51. 'New', 'NE', 'NSub','meanRT'});
  52. tmp = grpstats(dataCombine, {'New','NE','NSub'},{'mean','numel'}, 'datavars',{'meanRT'});
  53. dataOut.forSpss.RTAllCombine = dataset({reshape(tmp.mean_meanRT, Exp.subNum, []),...
  54. 'o1E1', 'o1E2', 'o1E3', 'o1E4', 'o1E5' ,'o1E6','o0E1', 'o0E2', 'o0E3', 'o0E4', 'o0E5', 'o0E6'} );
  55. else
  56. dataCombine = dataset( {[trainMeanSub_RT2.New2 trainMeanSub_RT2.NE trainMeanSub_RT2.NSub trainMeanSub_RT2.mean_RT2; ...
  57. testMeanSub_RT2.New1 testMeanSub_RT2.NE testMeanSub_RT2.NSub testMeanSub_RT2.mean_RT2;], ...
  58. 'New', 'NE', 'NSub','meanRT'});
  59. tmp = grpstats(dataCombine, {'New','NE','NSub'},{'mean','numel'}, 'datavars',{'meanRT'});
  60. dataOut.forSpss.RTAllCombine = dataset({reshape(tmp.mean_meanRT, Exp.subNum, []),...
  61. 'o1E1', 'o1E2', 'o1E3', 'o1E4', 'o1E5' ,'o1E6','o0E1', 'o0E2', 'o0E3', 'o0E4', 'o0E5', 'o0E6'} );
  62. end
  63. dataCombineMean = grpstats(dataCombine, {'New','NE'},{'mean','sem','numel'}, 'datavars',{'meanRT'});
  64. %plot all data together
  65. figure(); hold on; set(gcf,'Units','inches','Position',[2 2 6.83*0.5 6.83*0.5] );
  66. errorbar(1:5, dataCombineMean.mean_meanRT(1:5),dataCombineMean.sem_meanRT(1:5), 'k-o');
  67. errorbar(6, dataCombineMean.mean_meanRT(6),dataCombineMean.sem_meanRT(6), 'k-o');
  68. errorbar(1:5, dataCombineMean.mean_meanRT(7:11),dataCombineMean.sem_meanRT(7:11), 'k-*');
  69. errorbar(6, dataCombineMean.mean_meanRT(12), dataCombineMean.sem_meanRT(12), 'k-*');
  70. xlim([0.5 6.5]);
  71. ylabel('Reaction time (in Secs)');
  72. xlabel('Epochs');
  73. hold off;
  74. % nfig = ceil(sqrt(Exp.subNum) );
  75. % figure(); hold on;
  76. % for iSub = 1:Exp.subNum
  77. % train = trainMeanSub(trainMeanSub.NSub == iSub, :);
  78. % testEp6MeanSubTmp = testEp6MeanSub(testEp6MeanSub.NSub == iSub,:);
  79. % subplot(nfig,nfig,iSub); hold on;
  80. % plot(1:6, [train.mean_RT1(1:5); testEp6MeanSubTmp.mean_RT1(1) ]', 'r-o');
  81. % plot(1:6, [train.mean_RT1(6:10); testEp6MeanSubTmp.mean_RT1(2) ]', 'r-*');
  82. %
  83. % plot(1:6, [train.mean_RT2(1:5); testEp6MeanSubTmp.mean_RT2(1) ]', 'b-o');
  84. % plot(1:6, [train.mean_RT2(6:10); testEp6MeanSubTmp.mean_RT2(2) ]', 'b-*');
  85. %
  86. % ylabel('meanRT');
  87. % xlabel('Epochs');
  88. % set(gca,'XTick',[1:6]);
  89. % if iSub == 1
  90. % legend('oldLeft','newLeft','oldRight','newRight');
  91. % end
  92. % hold off
  93. % end
  94. %
  95. % %plot all subjects together, separate left and right participant
  96. % figure(); hold on;
  97. % errorbar(1:6, [trainMeanAllCombine.mean_mean_RT1(1:5); testEp6MeanAll.mean_mean_RT1(1) ], ...
  98. % [trainMeanAllCombine.sem_mean_RT1(1:5); testEp6MeanAll.sem_mean_RT1(1) ], 'r-o');
  99. % errorbar(1:6, [trainMeanAllCombine.mean_mean_RT1(6:10); testEp6MeanAll.mean_mean_RT1(2) ], ...
  100. % [trainMeanAllCombine.sem_mean_RT1(6:10); testEp6MeanAll.sem_mean_RT1(2) ],'r-*');
  101. %
  102. % errorbar(1:6, [trainMeanAllCombine.mean_mean_RT2(1:5); testEp6MeanAll.mean_mean_RT2(1) ],...
  103. % [trainMeanAllCombine.sem_mean_RT2(1:5); testEp6MeanAll.sem_mean_RT2(1) ], 'b-o');
  104. % errorbar(1:6, [trainMeanAllCombine.mean_mean_RT2(6:10); testEp6MeanAll.mean_mean_RT2(2) ], ...
  105. % [trainMeanAllCombine.sem_mean_RT2(6:10); testEp6MeanAll.sem_mean_RT2(2) ], 'b-*');
  106. %
  107. % ylabel('meanRT');
  108. % xlabel('Epochs');
  109. % set(gca,'XTick',[1:6]);
  110. % legend('oldLeft','newLeft','oldRight','newRight');
  111. % hold off;
  112. %
  113. catch ME
  114. disp(ME.message);
  115. end