MATLAB: How to count how many times disp() appears in the loop

countif statement

Hi,
I have created the following loop as a way to see how often the indexes doesn't equal to one. So every time, if condition is true, it displays YES. I want to know how to add up all the YES in the loop.
if indexes~=1;
disp('YES')
end

Best Answer

counter = 0;
if indexes~=1;
counter = counter + 1;
disp('YES')
end
sprintf('Value of counter = %d',counter)