How might I terminate a for loop based on an if statement?

2 次查看(过去 30 天)
I'm quite new to MATLAB and I believe this is a fairly simple question but I am hoping someone could help me with how to terminate this for loop when the condition of the if statement inside the loop becomes true? i.e. if a = [2,2,3,2] and b = [2,1,1,1] how might I be able to go about terminating the loop early so that numMatch = 1 when the loop has ended instead of having numMatch = 3?
a = [2,2,3,2]
b = [2,1,1,1];
numMatch = 0;
for (n = 1:4)
if (guess(1) == answer(n))
numMatch = numMatch + 1;
end
end

回答(1 个)

Stephen23
Stephen23 2019-7-17

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by