MATLAB: How to simplify the for loops and if statement in this code

confusionmatrixforfor loopif statement

How to simplify for loops and if statements.

Best Answer

Straightahead w/o trying to save some recomputations that could be done by complements--
k=[sum(A==B & A==0,'all') sum(A==B & A~=0,'all');sum(A~=B & A==0,'all') sum(A==B & A==1,'all')];