I have a function that will return me one of 3 different values: 0, -1, 1 (or 0, 1, 2).
Condition1 is more likely than condition2, and condition2 more likely than non of the condition being true, hence the elseif
function [A] = example(...)
if condition1 == true
A = 1;
elseif condition2 == true
A = -1;
else
A = 0;
end
I need to check the value A
, when doing that, will it be more efficient to see if A is positive or negative, or either 1 or 2?
Example 1:
if A > 0
% Do something
elseif A < 0
% Do something else
else
% Do nothing
end
Example 2:
if A == 1
% Do something
elseif A == 2
% Do something else
else
% Do nothing
end
Witch example will be most efficient cycle wise?