Matlab function searching for consecutive incorrect trials

[EDIT: 20110617 13:49 CDT - reformat - WDR]
Hi all,
I am currently analyzing data for an experiment that has 15 blocks of 40 trials each. In the experiment, if a participant answered incorrectly, a response code of "1" was generated in the fifth column of an output sheet, where there was one row for each trial (so, 600 rows of data total). I need to determine which blocks of 40 have at least one string of 3 consecutive incorrect trials. To do this, I created a Matlab function as part of a larger .m file. The formatting of the output data appears accurate, but some of the output values are incorrect (about half ARE correct - all before Block 9 except one are correct). Before Block 9, the only thing incorrect was that a correct datum was placed one cell to the right. The rest were correct. The opposite opposite of what was occuring after Block 9 - where the correct value for a particular cell was actually shown one cell to the left. At other times, there are seemingly meaningless numbers (such was "1" or "5") in cells that should read "0." My script follows. Thank you in advance for your help - I really appreciate it!
[B1Str, B2Str, B3Str, B4Str, B5Str, B6Str, B7Str, B8Str, B9Str, B10Str, B11Str, B12Str, B13Str, B14Str, B15Str] = StringsErrors(b)
B1Str=[];
B2Str=[];
B3Str=[];
B4Str=[];
B5Str=[];
B6Str=[];
B7Str=[];
B8Str=[];
B9Str=[];
B10Str=[];
B11Str=[];
B12Str=[];
B13Str=[];
B14Str=[];
B15Str=[];
counter=1;
StringPos=0;
% BLOCK 1
for row=1:38
f b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B1Str=StringPos;
end
% BLOCK 2
for row=41:78
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B2Str=StringPos-B1Str;
end
% BLOCK 3
for row=81:118
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B3Str=StringPos-B2Str-B1Str;
end
% BLOCK 4
for row=121:158
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B4Str=StringPos-B3Str-B2Str-B1Str;
end
% BLOCK 5
for row=161:198
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B5Str=StringPos-B4Str-B3Str-B2Str-B1Str;
end
% BLOCK 6
for row=201:238
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B6Str=StringPos-B5Str-B4Str-B3Str-B2Str-B1Str;
end
% BLOCK 7
for row=241:278
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B7Str=StringPos-B6Str-B5Str-B4Str-B3Str-B2Str-B1Str;
end
% BLOCK 8
for row=281:318
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B8Str=StringPos-B7Str-B6Str-B5Str-B4Str-B3Str-B2Str-B1Str;
end
% BLOCK 9
for row=321:358
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B9Str=StringPos-B8Str-B7Str-B6Str-B5Str-B4Str-B3Str-B2Str-B1Str;
end
% BLOCK 10
for row=361:398
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B10Str=StringPos-B9Str-B8Str-B7Str-B6Str-B5Str-B4Str-B3Str-B2Str-B1Str;
end
% BLOCK 11
for row=401:438
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B11Str=StringPos-B10Str-B9Str-B8Str-B7Str-B6Str-B5Str-B4Str-B3Str-B2Str-B1Str;
end
% BLOCK 12
for row=441:478
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B12Str=StringPos-B11Str-B10Str-B9Str-B8Str-B7Str-B6Str-B5Str-B4Str-B3Str-B2Str-B1Str;
end
% BLOCK 13
for row=481:518
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B13Str=StringPos-B12Str-B11Str-B10Str-B9Str-B8Str-B7Str-B6Str-B5Str-B4Str-B3Str-B2Str-B1Str;
end
% BLOCK 14
for row=521:558
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B14Str=StringPos-B13Str-B12Str-B11Str-B10Str-B9Str-B8Str-B7Str-B6Str-B5Str-B4Str-B3Str-B2Str-B1Str;
end
% BLOCK 15
for row=561:598
if b(counter,5)==1 && b(counter+1,5)==1 && b(counter+2,5)==1;
StringPos=StringPos+1;
counter=counter+1;
else
counter=counter+1;
end
B15Str=StringPos-B14Str-B13Str-B12Str-B11Str-B10Str-B9Str-B8Str-B7Str-B6Str-B5Str-B4Str-B3Str-B2Str-B1Str;
end
end

回答(0 个)

类别

Community Treasure Hunt

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

Start Hunting!

Translated by