Octave – espressioni I – 33

mrreuleaux

Proseguendo da qui copio qui.

Espressioni

Expressions are the basic building block of statements in Octave. An expression evaluates to a value, which you can print, test, store in a variable, pass to a function, or assign a new value to a variable with an assignment operator.

An expression can serve as a statement on its own. Most other kinds of statements contain one or more expressions which specify data to be operated on. As in other languages, expressions in Octave include variables, array references, constants, and function calls, as well as combinations of these with various operators.

OK, passo qui.

Espressioni index
An index expression allows you to reference or extract selected elements of a matrix or vector.
Indices may be scalars, vectors, ranges, or the special operator ‘:’, which may be used to select entire rows or columns.
Vectors are indexed using a single index expression. Matrices (2-D) and higher multi-dimensional arrays are indexed using either one index or N indices where N is the dimension of the array. When using a single index expression to index 2-D or higher data the elements of the array are taken in column-first order (like Fortran).
The output from indexing assumes the dimensions of the index expression. For example:

a(2)       # result is a scalar
a(1:2)     # result is a row vector
a([1; 2])  # result is a column vector

Nota: le parentesi devono essere quelle.

As a special case, when a colon is used as a single index, the output is a column vector containing all the elements of the vector or matrix. For example:

a(:)       # result is a column vector
a(:)'      # result is a row vector

The above two code idioms are often used in place of reshape when a simple vector, rather than an arbitrarily sized array, is needed.

Given the matrix a = [1, 2; 3, 4] all of the following expressions are equivalent and select the first row of the matrix:

o208

In index expressions the keyword end automatically refers to the last entry for a particular dimension. This magic index can also be used in ranges and typically eliminates the needs to call size or length to gather array bounds before indexing. For example:

o209

:mrgreen:

Posta un commento o usa questo indirizzo per il trackback.

Trackback

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: