Repeating If statement after variable change
古いコメントを表示
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
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Sudoku についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!