find beginning and end of events in a loop
5 次查看(过去 30 天)
显示 更早的评论
Hi,
i have the diameter left and right (DialL and DialR) and the variable TOBII_Stim (=Stimulus).
I am trying to extract the DialL and DialR that correspon to specific condtions presents in the variable TOBII_Stim. For example, i have to extract the diameter L and R that goes from the beginning of the condition "Croix grise 200" until the end of the condition "Croix grise 200".
to do so, i created two empy variables that i will fulfill with the index of my beginning and end condition:
index_trial=[];
index_trial_end=[];
for i=1:length(TOBII_Stim)
if TOBII_Stim(i) == "Croix grise 200.jpg"
index_trial(end+1) = i;
elseif TOBII_Stim(i) == "Croix grise 85.jpg"
index_trial(end+1) = i;
elseif TOBII_Stim(i) == "Croix grise 255.jpg"
index_trial(end+1) = i;
elseif TOBII_Stim(i) == "RichText4.rtf"
index_trial(end+1) = i;
elseif TOBII_Stim(i) == "RichText3.rtf"
index_trial(end+1) = i;
elseif TOBII_Stim(i) == "RichText2.rtf"
index_trial(end+1) = i;
elseif TOBII_Stim(i) == "RichText1.rtf"
index_trial(end+1) = i;
end
end
i tried several things to find the end but i have errors saying that values must be integers.
Could please somebody help me out with understanding how to find the END of each condition and fulfill the variable index_trial_end=[]; ?
thnak you in advance
2 个评论
回答(1 个)
Divyanshu
2023-4-21
The reason for the error is that ‘TOBII_Stim’ is a cellular array and you are trying to access the elements of the cellular array using parenthesis () instead the cellular array elements should be accessed using angular brackets {}.
Have a look at the below sample code for better understanding:
index_trial=[];
index_trial_end=[];
TOBII_Stim = {"Validation.jpg" "RichText4.rtf" "Croix grise 200.jpg" "Croix grise 500.jpg" "Validation.jpg"}';
for i=1:length(TOBII_Stim)
if TOBII_Stim{i} == "Croix grise 200.jpg"
index_trial(end+1) = i;
elseif TOBII_Stim{i} == "Croix grise 85.jpg"
index_trial(end+1) = i;
elseif TOBII_Stim{i} == "Croix grise 255.jpg"
index_trial(end+1) = i;
elseif TOBII_Stim{i} == "RichText4.rtf"
index_trial(end+1) = i;
elseif TOBII_Stim{i} == "RichText3.rtf"
index_trial(end+1) = i;
elseif TOBII_Stim{i} == "RichText2.rtf"
index_trial(end+1) = i;
elseif TOBII_Stim{i} == "RichText1.rtf"
index_trial(end+1) = i;
end
end
index_trial
Please refer the following documentation for further information:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!