how to finds consecutive numbers in an array
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I have a question about finding consecutive numbers in a matlab array.
Currently my script imports .log files that are created by a experiment run on Presentation. In the array this creates I see all of the trigger codes, but I only want to know when a specific trigger code happens followed by a different trigger code (button press)
This is what I came up with so far but I am stuck.
clear all
dir='C:\Users\Desktop\paradigm\'
total_blocks = 1 %amount of blocks
data1 = []
for blocks=1:total_blocks
[x] =importPresentationLog([dir '10049-Entrain_Vis' num2str(blocks) '.txt']); %importing logfile
data1 = [data1, x] % all info from all the logfiles go here.
end
No_of_Trials=length(data1);
for i=1:No_of_Trials
trigger{i}=(data1(:,i).code);
Time{i}=(data1(:,i).time);
end
[INDEX_CODE42]=find(strcmp(trigger,'42')==1) %%finding the definde trigger (42) and creating an index
However I want to look specifically for '42' followed by '100' OR '42' followed by any possible trigger followed by '100'
Next42=trigger(INDEX_CODE42+1); %gives the triggers following the previous one (42)
code100=[INDEX_CODE100]
NextNext42=trigger(INDEX_CODE42+2)%gives the second triggers following the previous one (42)
Time42=Time(INDEX_CODE42+1);
Time42x=Time(INDEX_CODE42)
RT = cellfun(@minus,Time42,Time42x,'UniformOutput',false)
This part works but since it includes every 42 trigger and not only the correct ones ( the ones followed by a button press) I include all the trials that didn't get a respons.
I hope someone is able to help me out with this.
Thank you so much!
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!