Storing as a choice. and randomly picking between to choices.

2 views (last 30 days)
So im making this program with an if loop that goes as follows:
moves:[0,0,1;1,1,0;0,0,1];
if board(moves(a,1))==1 && board(moves(a,2))==1 && board(moves(a,3))==0;
-----since this conditional statement can be true more than once, is there any way for me to HOLD ON to the first time that it is true in order to see if it can be true for multiple times. Then I would randomly choose from those satisfied statements to execute a command?
  2 Comments
Walter Roberson
Walter Roberson on 7 May 2014
There is no such thing as an "if loop". There are "for loops" and "while loops" and "if statements". "if" executes code exactly 0 or 1 times; loops can have any representable number of iterations.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 7 May 2014
I think what you want is:
selected = board(moves(:,1))==1 & board(moves(:,2))==1 & board(moves(:,3))==0;
and then selected would be a logical vector, true in position K if row K matched. You could find() on the result if you wanted.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!