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

Precedence of and and or Operators

MATLAB always gives the & operator precedence over the | operator. Although MATLAB typically evaluates expressions from left to right, the expression a|b&c is evaluated as a|(b&c). It is a good idea to use parentheses to explicitly specify the intended precedence of statements containing combinations of & and |.

The same precedence rule holds true for the && and || operators.

  • R2013a>MATLAB>Language Fundamentals>Special Characters

  • Symbol Reference

On this page…

Asterisk — *

At — @

Colon — :

Comma — ,

Curly Braces — { }

Dot — .

Dot-Dot — ..

Dot-Dot-Dot (Ellipsis) — ...

Dot-Parentheses — .( )

Exclamation Point — !

Parentheses — ( )

Percent — %

Percent-Brace — %{ %}

Plus — +

Semicolon — ;

Single Quotes — ' '

Space Character

Slash and Backslash — / \

Square Brackets — [ ]

Tilde — ~

Asterisk — *

An asterisk in a filename specification is used as a wildcard specifier, as described below.

Filename Wildcard

Wildcards are generally used in file operations that act on multiple files or folders. They usually appear in the string containing the file or folder specification. MATLAB® matches all characters in the name exactly except for the wildcard character *, which can match any one or more characters.

To locate all files with names that start with 'january_' and have a mat file extension, use

dir('january_*.mat')

You can also use wildcards with the who and whos functions. To get information on all variables with names starting with 'image' and ending with 'Offset', use

whos image*Offset

At — @

The @ sign signifies either a function handle constructor or a folder that supports a MATLAB class.

Function Handle Constructor

The @ operator forms a handle to either the named function that follows the @ sign, or to the anonymous function that follows the @ sign.

Function Handles in General.  Function handles are commonly used in passing functions as arguments to other functions. Construct a function handle by preceding the function name with an @ sign:

fhandle = @myfun

For more information, see function_handle (R2013a>MATLAB>Language Fundamentals>Data Types>Function Handles).

Handles to Anonymous Functions.  Anonymous functions give you a quick means of creating simple functions without having to create your function in a file each time. You can construct an anonymous function and a handle to that function using the syntax

fhandle = @(arglist) body

where body defines the body of the function and arglist is the list of arguments you can pass to the function.

See Anonymous Functions (R2013a>MATLAB>Programming Scripts and Functions>Functions>Function Basics) for more information.

Class Folder Designator

An @ sign can indicate the name of a class folder, such as

\@myclass\get.m

See the documentation on Options for Class Folders (R2013a>MATLAB>Advanced Software Development>Object-Oriented Programming>Defining MATLAB Classes>Class Definition and Organization>Organizing Classes in Folders) for more information.

Colon — :

The colon operator generates a sequence of numbers that you can use in creating or indexing into arrays. See Generating a Numeric Sequence (R2013a>MATLAB>Language Fundamentals>Matrices and Arrays>Array Creation and Concatenation>Creating and Concatenating Matrices) for more information on using the colon operator.

Numeric Sequence Range

Generate a sequential series of regularly spaced numbers from first to last using the syntax first:last. For an incremental sequence from 6 to 17, use

N = 6:17

Numeric Sequence Step

Generate a sequential series of numbers, each number separated by a step value, using the syntax first:step:last. For a sequence from 2 through 38, stepping by 4 between each entry, use

N = 2:4:38

Indexing Range Specifier

Index into multiple rows or columns of a matrix using the colon operator to specify a range of indices:

B = A(7, 1:5); % Read columns 1-5 of row 7.

B = A(4:2:8, 1:5); % Read columns 1-5 of rows 4, 6, and 8.

B = A(:, 1:5); % Read columns 1-5 of all rows.

Conversion to Column Vector

Convert a matrix or array to a column vector using the colon operator as a single index:

A = rand(3,4);

B = A(:);

Preserving Array Shape on Assignment

Using the colon operator on the left side of an assignment statement, you can assign new values to array elements without changing the shape of the array:

A = rand(3,4)

A =

0.9572 0.1419 0.7922 0.0357

0.4854 0.4218 0.9595 0.8491

0.8003 0.9157 0.6557 0.9340

A(:) = 1:12;

A

A =

1 4 7 10

2 5 8 11

3 6 9 12

Comma — ,

A comma is used to separate the following types of elements.

Row Element Separator

When constructing an array, use a comma to separate elements that belong in the same row:

A = [5.92, 8.13, 3.53]

Array Index Separator

When indexing into an array, use a comma to separate the indices into each dimension:

X = A(2, 7, 4)

Function Input and Output Separator

When calling a function, use a comma to separate output and input arguments:

function [data, text] = xlsread(file, sheet, range, mode) (выходные аргументы можно разделять пробелами)

Command or Statement Separator

To enter more than one MATLAB command or statement on the same line, separate each command or statement with a comma:

for k = 1:10, sum(A(k)), end (возможно также разделение команд оператором ограничения вывода ;)

Curly Braces — { }

Use curly braces to construct or get the contents of cell arrays.

Cell Array Constructor

To construct a cell array, enclose all elements of the array in curly braces:

C = {[2.6 4.7 3.9], rand(8)*6, 'C. Coolidge'} (возможно перенесение скобок влево: C{:}= [2.6 4.7 3.9], rand(8)*6, 'C. Coolidge')

Cell Array Indexing

Index to a specific cell array element by enclosing all indices in curly braces:

A = C{4,7,2} (присваивание переменной A значения ячейки в массиве C; другой случай: C{4,7,2}= A - заполнение ячейки массива C значением A)

For more information, see Cell Arrays (R2013a>MATLAB>Language Fundamentals>Data Types).

Dot — .

The single dot operator has the following different uses in MATLAB.

Decimal Point

MATLAB uses a period to separate the integral and fractional parts of a number.

Structure Field Definition

Add fields to a MATLAB structure by following the structure name with a dot and then a field name:

funds(5,2).bondtype = 'Corporate';

For more information, see Structures (R2013a>MATLAB>Language Fundamentals>Data Types).

Object Method Specifier (лучше Object Property Specifier, потому что Method - это процедура-функция)

Specify the properties of an instance of a MATLAB class using the object name followed by a dot, and then the property name:

val = asset.current_value

Dot-Dot — ..

Two dots in sequence refer to the parent of the current folder.

Parent Folder

Specify the folder immediately above your current folder using two dots. For example, to go up two levels in the folder tree and down into the test folder, use

cd ..\..\test

Dot-Dot-Dot (Ellipsis) — ...

A series of three consecutive periods (...) is the line continuation operator in MATLAB. This is often referred to as an ellipsis, but it should be noted that the line continuation operator is a three-character operator and is different from the single-character ellipsis represented in ASCII by the hexadecimal number 2026.