12.07.2015 Views

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 18: Matrix Manipulation 14918 Matrix ManipulationThere are a number of functions available for checking to see if the elements of a matrixmeet some condition, and for rearranging the elements of a matrix. For example, <strong>Octave</strong>can easily tell you if all the elements of a matrix are finite, or are less than some specifiedvalue. <strong>Octave</strong> can also rotate the elements, extract the upper- or lower-triangular parts, orsort the columns of a matrix.18.1 Finding Elements and Checking ConditionsThe functions any and all are useful for determining whether any or all of the elementsof a matrix satisfy some condition. The find function is also useful in determining whichelements of a matrix meet a specified condition.any (x, dim)Built-in FunctionFor a vector argument, return 1 if any element of the vector is nonzero.For a matrix argument, return a row vector of ones and zeros with each elementindicating whether any of the elements of the corresponding column of the matrix arenonzero. For example,any (eye (2, 4))⇒ [ 1, 1, 0, 0 ]If the optional argument dim is supplied, work along dimension dim. For example,any (eye (2, 4), 2)⇒ [ 1; 1 ]all (x, dim)Built-in FunctionThe function all behaves like the function any, except that it returns true only ifall the elements of a vector, or all the elements along dimension dim of a matrix, arenonzero.Since the comparison operators (see Section 10.4 [Comparison Ops], <strong>page</strong> 70) returnmatrices of ones and zeros, it is easy to test a matrix for many things, not just whether theelements are nonzero. For example,all (all (rand (5) < 0.9))⇒ 0tests a random 5 by 5 matrix to see if all of its elements are less than 0.9.Note that in conditional contexts (like the test clause of if and while statements) <strong>Octave</strong>treats the test as if you had typed all (all (condition)).xor (x, y)Mapping FunctionReturn the ‘exclusive or’ of the entries of x and y. For boolean expressions x and y,xor (x, y) is true if and only if x or y is true, but not if both x and y are true.is duplicate entry (x)Return non-zero if any entries in x are duplicates of one another.Function File

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!