www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/UseScalarLogicalConditionsExample.m

    %% Use Scalar Logical Conditions  

%% 
% Create two vectors. 
X = [1 0 0 1 1];
Y = [0 0 0 0 0];  

%% 
% Using the short-circuit OR operator with |X| and |Y| returns an error.
% The short-circuit operators operate only with scalar logical conditions.

%% 
% Use the |any| and |all| functions to reduce each vector to a single
% logical condition.
any(X) || any(Y) 

%%
% The expression is equivalent to |1 OR 0|, so it evaluates to logical |1|
% (|true|) after computing only the first condition, |any(X)|.