MATLAB: Conditional (IF) Statement Help. Using a variable to “toggle” the status of an IF statement.

toggle matlab mgl if statements conditional logical help

What I'm trying to do is have my function proceed if certain conditions are met. And if a certain condition is met, then it toggles it into a state to go back and run the if statements again. I'm still learning matlab and I need to edit code for my research and don't know where to start. I am running most of my stuff through MGL. But the MGL part is slightly irrelevant to my question. I'm basically setting an experiment to do a certain task at a very specific moment in time. What I'm trying to do is create a randomized occurrence of this task (which I have already figured out) at set intervals that I created. What I want to do is have the IF statements toggle to whether or not they have occurred.
task{1}.parameter.tmstrigger = [0 1 2]; %trigger tms coil, 100ms, 250ms,400ms in that order
stimulus.initTime=mglGetSecs() %if you're not familiar with this, it's similar to the TIC/TOC function
stimulus.t2 = mglGetSecs(stimulus.initTime);
variable = [0 1]; %this is what I'm unsure of
if task.thistrial.tmstrigger==0; %0.1ms
if stimulus.t2greaterequal10
disp('check')
What I want to happen after this "disp('check')" is for the state of task.thistrial.tmstrigger==0; to toggle into a position that tells the program that it's already happened. After the task.thistrial.tmstrigger==0; I'm going to have a task.thistrial.tmstrigger==1; and a task.thistrial.tmstrigger==2 with very similar patterns. The format of what I'm trying to do is as follows (I just don't know how to write the code to do so):
task{1}.parameter.tmstrigger = 0; %[0 1 2]; %trigger tms coil, 100ms, 250ms,400ms in that order
Collect the time (which I already have with mglGetSecs)
...other code I didn't include in this post that's irrelevant...
some sort of toggle variable??
if tmstrigger ==0
if stimulus.t2>= .10 %%%can I rewirete this as (if tmstrigger== 0 & stimulus.t2>=.1)?
disp('check')
end
SOMEHOW TOGGLE THIS TO SAY THE t2>.10 HAS HAPPENED AND NOT GO BACK TO THIS IF
end
if tmstrigger ==1
same format
if tmstrigger ==2
same format
I really hope my question isn't too confusing. I'm a noob at matlab and still trying to understand the very basic logical stuff.
Thank you!

Best Answer

Try something like:
needToDisplay = true;
for k = 1:10
if needToDisplay && k >= 5 % the first AND second conditions must be satisfied
fprintf('Currently, k is %d\n', k);
needToDisplay = false;
end
if k == 8
needToDisplay = true;
end
end
This should display for k = 5 (needToDisplay is true and 5 is greater than or equal to 5) and k = 9 (needToDisplay is true, it was changed when k was equal to 8 inside the second IF statement, and 9 is greater than or equal to 5.) It should not display for any other number, as either needToDisplay is false (for k = 6, 7, 8, and 10) or k >= 5 is false (for k = 1, 2, 3, 4.)
If you wanted to display if either the first OR the second conditions (or both) were satisfied, use || instead of &&.