How to use break/continue?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!