14.09.2015 Views

Matvec Users’ Guide

Matvec Users' Guide

Matvec Users' Guide

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.3. MANIPULATION 17<br />

3.2.2 Relational operators<br />

There are six relational operators, they operate between two objects.<br />

== equal to<br />

!= not equal to<br />

< less than<br />

> greater than<br />

= greater than or equal to<br />

These six operators are based on element-by-element comparison. It returns a matrix with resulting<br />

element(i,j) = 1.0 if the relationship is true, otherwise resulting element(i,j) = 0.0<br />

3.2.3 Logical operators<br />

There are two sets of logical operators: (&&, ||) and (.&&, .||).<br />

The && is a short-circuit logical operator AND. A && B returns 1 if both A and B are true (B is evaluated<br />

only after A is true), otherwise return 0. If A (or B) is a matrix, then A.all().all() is implicitly applied. If<br />

A (or B) is a vector, then A.all() is implicitly applied. Any other types of objects will be determined false.<br />

The || is a short-circuit logical operator OR. A || B returns 1 if either A and B are true (B is evaluated<br />

only after A is false), otherwise return 0. If A (or B) is a matrix, then A.all().all() is implicitly applied. If<br />

A (or B) is a vector, then A.all() is implicitly applied. Any other types of objects will be determined false.<br />

The .&& and .|| are the same as && and || except that 1) the former is performed element-by-element,<br />

2) the former is non-short-circuit, thus both operands will be evaluated.<br />

For readability, <strong>Matvec</strong> creates synonyms AND and OR for && and ||, respectively.<br />

3.3 Manipulation<br />

Matrix manipulation is a tricky work. Basically, there are three kinds of manipulations: 1) accessing elements<br />

and sub-matrices, 2) adjoining and stacking, 3) selecting elements which satisfy whatever condition you<br />

specify. They are described below in detail.<br />

3.3.1 Accessing element and sub-matrix<br />

• accessing an element<br />

A(i,j) accesses (i,j)’th element with boundary checking<br />

• accessing a row<br />

A(i,*) gets a copy of the i’th row of matrix A.<br />

• accessing a column<br />

A(*,j) gets a copy of the j’th column of matrix A.<br />

• accessing sub-matrix<br />

A(i1:i2, j1:j2) returns a sub-matrix of A with row i1 through i2 and column j1 through j2. A([i1,i2,i3],<br />

[j1,j2,j3]) returns a sub-matrix of A with rows i1, i2, and i3 and columns j1, j2, and j3.<br />

For example,

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

Saved successfully!

Ooh no, something went wrong!