%--------------------------------------------------------- % % For A321 course % %------------------------------------------------------------- % % Randall Bramley % Department of Computer Science % Indiana University, Bloomington % bramley somewhere at cs dot indiana dot (allegedly) edu % % Started: Mon 04 Feb 2008, 09:05 AM % Last Modified: Mon 16 Feb 2009, 03:42 PM % %------------------------------------------------------------- more on echo on %--------------------------------------------------------- % Logical operators return 0 (false) or 1 (true). This % is a bad programming practice but started with C coding % back in the 1970's and now it is deeply embedded in much % of numerical computing. %--------------------------------------------------------- %------------------------------------------- % First, set up a simple vector to work with %------------------------------------------- a = 1:9 % greater than is > t1 = a > 4 % less than is < t2 = a < 4 % greater than or equal to is >= t3 = a >= 4 % less than or equal to is <= t4 = a <= 4 %-------------------------------------------------------------- % Notice that the last two have the inequality operator (<, >) % appearing *before* the equality operator (=). %-------------------------------------------------------------- %----------------------------------------------------------------- % The next is a test for where a is equal to 4, not to be confused % with the assignment statement % a = 4 % which would reset the 1x9 vector a to be the 1x1 scalar value 4 %----------------------------------------------------------------- t5 = a == 4 t6 = a ~= 4 %--------------------------------------------------------------- % The inequality operator ~= can take the forms % != % /= % ^= % .ne. % in other languages, so it's one to check on in each case. % The others are standard in C, C++, Fortran, Perl, Python, .... % % The find() function is not the same; it returns a set of % indices, not just true or false (or 1 and 0). %--------------------------------------------------------------- I = find(a >= 4) echo off; more off;