Repeating If statement after variable change
Show older comments
Hello! I have a question about the usage of 'return' and/or 'repeat.' I have an if statement that takes in an m x 1 vector (lets call it SS) and outputs a common number vector between specified arrays above it in the function. However, if the length of the common number vector is greater than one, then I would change the SS input and repeat the first if statement. How would I do this without making a nested or subfunction? Thank you!
%A simplified example:
A = [1 2 3 4];
B = [1 2 6];
C = [1 7];
if SS(1)==1;
commonnums = intersect(A,B); %commonnums would be [1 2]
if length(commonnums)>1;
SS = SS + 1;
%repeat first if statement with SS(1)==2;
else
commonnums = commonnums;
end
elseif SS(1)==2;
commonnums = intersect(A,C); %commonnums would now be [1]
if length(commonnums)>1;
SS = SS + 1;
%repeat first if statement with SS(1)==3;
else
commonnums = commonnums;
end
elseif SS(1)==3;
commonnums = intersect(B,C); %commonnums would be [1] also
if length(commonnums)>1;
SS = SS - 2;
%repeat first if statement with SS(1)==1;
else
commonnums = commonnums;
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Sudoku 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!