Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Одиноков / МиИПиС_асп_13г / MATLAB_R2013a_Выбор.doc
Скачиваний:
33
Добавлен:
15.04.2015
Размер:
4.03 Mб
Скачать

Indexing on Assignment

When assigning values from one matrix to another matrix, you can use any of the styles of indexing covered in this section. Matrix assignment statements also have the following requirement.

In the assignment A(J,K,...) = B(M,N,...), subscripts J, K, M, N, etc. may be scalar, vector, or array, provided that all of the following are true:

  • The number of subscripts specified for B, not including trailing subscripts equal to 1, does not exceed ndims(B) (число измерений для B).

  • The number of nonscalar subscripts specified for A equals the number of nonscalar subscripts specified for B. For example, A(5, 1:4, 1, 2) = B(5:8) is valid because both sides of the equation use one nonscalar subscript.

  • The order and length of all nonscalar subscripts specified for A matches the order and length of nonscalar subscripts specified for B. For example, A(1:4, 3, 3:9) = B(5:8, 1:7) is valid because both sides of the equation (ignoring the one scalar subscript 3) use a 4-element subscript followed by a 7-element subscript.

  • R2013a>MATLAB>Language Fundamentals>Operators and Elementary Operations>Arithmetic

  • Arithmetic Operators

Arithmetic operators perform numeric computations, for example, adding two numbers or raising the elements of an array to a given power. The following table provides a summary. For more information, see the arithmetic operators (R2013a>MATLAB>Language Fundamentals>Operators and Elementary Operations>Arithmetic) reference page.

Operator

Description

+

Addition

-

Subtraction

.*

Multiplication

./

Right division

.\

Left division

+

Unary plus

-

Unary minus

:

Colon operator

.^

Power

.'

Transpose

'

Complex conjugate transpose

*

Matrix multiplication

/

Matrix right division

\

Matrix left division

^

Matrix power

Arithmetic Operators and Arrays

Except for some matrix operators, MATLAB® arithmetic operators work on corresponding elements of arrays with equal dimensions. For vectors and rectangular arrays, both operands must be the same size unless one is a scalar. If one operand is a scalar and the other is not, MATLAB applies the scalar to every element of the other operand—this property is known as scalar expansion.

This example uses scalar expansion to compute the product of a scalar operand and a matrix.

A = magic(3)

A =

8 1 6

3 5 7

4 9 2

3 * A

ans =

24 3 18

9 15 21

12 27 6

  • R2013a>MATLAB>Language Fundamentals>Operators and Elementary Operations>Arithmetic

  • Operator Precedence

You can build expressions that use any combination of arithmetic, relational, and logical operators. Precedence levels determine the order in which MATLAB evaluates an expression. Within each precedence level, operators have equal precedence and are evaluated from left to right. The precedence rules for MATLAB operators are shown in this list, ordered from highest precedence level to lowest precedence level:

  1. Parentheses ()

  2. Transpose (.'), power (.^), complex conjugate transpose ('), matrix power (^)

  3. Unary plus (+), unary minus (-), logical negation (~)

  4. Multiplication (.*), right division (./), left division (.\), matrix multiplication (*), matrix right division (/), matrix left division (\)

  5. Addition (+), subtraction (-)

  6. Colon operator (:)

  7. Less than (<), less than or equal to (<=), greater than (>), greater than or equal to (>=), equal to (==), not equal to (~=)

  8. Element-wise AND (&)

  9. Element-wise OR (|)

  10. Short-circuit AND (&&)

  11. Short-circuit OR (||)