How to use break/continue?

4 次查看(过去 30 天)
Sherwin
Sherwin 2022-4-26
Hi, I have the following matrices,
AT = [1 1 0 0 0 ; 0 0 1 1 0; 1 0 0 1 1]; % a 3*5 matrix
yHT = [1 ; 1 ; 0 ; 0 ; 1]; % a 5*1 array
I want to use loops to go through these two matrices and for each row of AT, for all elements that are 1, if the respective element on yHT is 1 too, return 1, if not, then return 0 (even if only 1 respective element on yHT is 0 it should return 0); and then repeat this for every row of AT. I tried the following loop but it I think I am using break or continue wrong or maybe my whole code is wrong. Can someone please help me?
for i = 1:3
counter = 0;
for j = 1:5
if AT(i,j) == 1
if yHT(j,1) == 1
counter = 1;
break
else
counter = 0;
continue
end
else
counter = 0;
continue
end
end
end
  3 个评论
Sherwin
Sherwin 2022-4-26
Is it the same as &&?
Walter Roberson
Walter Roberson 2022-4-26
&& is restricted to scalars.

请先登录,再进行评论。

回答(0 个)

类别

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