Logic: + logical values: 0 (false) and 1 (true) (actually, anything non-zero is true) + logical operators: & (and), | (or), ~ (not), xor (exclusive or) + relational operators: >, >=, <, <=, ==, ~= + examples) 1 < 2 % less than 1 == 1 % equal (true) 1 == 2 % equal (false) 1==1 & 2==2 % true 1 > 2 | 1 < 2 % true xor(1 < 2,1 < 3) % false 5 & 10 % true (anything non-zero is technically true!) ------------------------------------------------------------------------------- Logical Arrays + an array of logical values + operations are applied to each element one at a time + MATLAB stores 1 or 0 depending on the truth of the relation for each element >> x = [1 2 3]; >> y = x >= 2 + to extract elements that correspond to TRUE relations, use array(logicalarray) >> x(y) + Example 2: find even integers from an array >> z = 0:10; % array from 0 to 10 >> k = mod(z,2)==0; % $k$ is a logical array >> z(k) % extract even integers from $k$ + WARNING: to generate logical array, MUST use relations, not just enter 0 and 1! >> z=3:5; % array of ints from 3 to 5 >> q=[0 1 0]; % array of what appears to be logical values (but isn't!) >> z(q) % attempt to extract elements from $z$ (but won't work) output is the error mesg: ??? Index into matrix is negative or zero. See release notes on changes to logical indices. >> To fix, use $logical$ function: >> z(logical(q)) -------------------------------------------------------------------------------