MATLAB: If else

homeworkif else counter

i need to compare s=[0 1] with I=[0 0;1 1;1 0;0 1;1 0;0 0; 1 0; 1 1; 0 0;………………………..90bits] i want to use counter .can any one help me

Best Answer

s=[0 1];
I=[0 0;1 1;1 0;0 1;1 0;0 0; 1 0; 1 1; 0 0]
counter=0;
for n=1:size(I,1)
if I(n,:)==s
counter=counter+1;
else
%nothing to be done, just included the else for fun :)
end
end
counter
Alternative just for fun
s=[0 1];
I=[0 0;1 1;1 0;0 1;1 0;0 0; 1 0; 1 1; 0 0]
counter=0;
for n=1:size(I,1)
if I(n,:)~=s
%nothing to be done here :)
else
counter=counter+1;
end
end
counter