www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ReduceALogicalVectorToASingleConditionAnyExample.m
%% Reduce a Logical Vector to a Single Condition %% % Create a vector of decimal values and test which values are less than % 0.5. A = [0.53 0.67 0.01 0.38 0.07 0.42 0.69]; B = (A < 0.5) %% % The output is a vector of logical values. The |any| function reduces such % a vector of logical values to a single condition. In this case, |B = % any(A < 0.5)| yields logical |1|. %% % This makes |any| particularly useful in |if| statements. % % if any(A < 0.5) % %do something % else % %do something else % end % %% % The code is executed depending on a single condition, rather than a % vector of possibly conflicting conditions.