find beginning and end of events in a loop
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Divyanshu
on 21 Apr 2023
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 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!