필터 지우기
필터 지우기

How to use break/continue?

조회 수: 4 (최근 30일)
Sherwin
Sherwin 2022년 4월 26일
댓글: Walter Roberson 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