
- •Matlab r2013a стр. 225
- •Continue Long Statements on Multiple Lines
- •Creating and Concatenating Matrices
- •Overview
- •Constructing a Simple Matrix
- •Entering Signed Numbers
- •Specialized Matrix Functions
- •Examples
- •Concatenating Matrices
- •Keeping Matrices Rectangular
- •Matrix Concatenation Functions
- •Examples
- •Generating a Numeric Sequence
- •The Colon Operator
- •Using the Colon Operator with a Step Value
- •Matrix Indexing
- •Accessing Single Elements
- •Linear Indexing
- •Functions That Control Indexing Style
- •Accessing Multiple Elements
- •Nonconsecutive Elements
- •The end Keyword
- •Specifying All Elements of a Row or Column
- •Using Logicals in Array Indexing
- •Logical Indexing – Example 1
- •Logical Indexing – Example 2
- •Logical Indexing with a Smaller Array
- •Single-Colon Indexing with Different Array Types
- •Indexing on Assignment
- •Arithmetic Operators
- •Arithmetic Operators and Arrays
- •Operator Precedence
- •Precedence of and and or Operators
- •Overriding Default Precedence
- •Relational Operators and Arrays
- •Relational Operators and Empty Arrays
- •Overview of the Logical Class
- •Logical Operators
- •Element-Wise Operators and Functions
- •Short-Circuit Operators
- •Precedence of and and or Operators
- •Symbol Reference
- •Asterisk — *
- •Filename Wildcard
- •Function Handle Constructor
- •Class Folder Designator
- •Line Continuation
- •Dynamic Structure Fields
- •Exclamation Point — !
- •Semicolon — ;
- •Array Row Separator
- •Output Suppression
- •Command or Statement Separator
- •Single Quotes — ' '
- •Square Brackets — [ ]
- •Fundamental matlab Classes
- •More About
- •Overview of Numeric Classes
- •Integers
- •Integer Classes
- •Creating Integer Data
- •Arithmetic Operations on Integer Classes
- •Largest and Smallest Values for Integer Classes
- •Integer Functions
- •Floating-Point Numbers
- •Double-Precision Floating Point
- •Single-Precision Floating Point
- •Creating Floating-Point Data
- •Creating Double-Precision Data
- •Creating Single-Precision Data
- •Arithmetic Operations on Floating-Point Numbers
- •Double-Precision Operations
- •Single-Precision Operations
- •Largest and Smallest Values for Floating-Point Classes
- •Largest and Smallest Double-Precision Values
- •Largest and Smallest Single-Precision Values
- •Accuracy of Floating-Point Data
- •Double-Precision Accuracy
- •Single-Precision Accuracy
- •Avoiding Common Problems with Floating-Point Arithmetic
- •Example 1 — Round-Off or What You Get Is Not What You Expect
- •Example 2 — Catastrophic Cancellation
- •Example 3 — Floating-Point Operations and Linear Algebra
- •Floating-Point Functions
- •Creating a Rectangular Character Array
- •Combining Strings Vertically
- •Combining Strings Horizontally
- •Identifying Characters in a String
- •Working with Space Characters
- •Expanding Character Arrays
- •String Comparisons
- •Comparing Strings for Equality
- •Comparing for Equality Using Operators
- •Categorizing Characters Within a String
- •Create a Structure Array
- •Access Data in a Structure Array
- •Concatenate Structures
- •Generate Field Names from Variables
- •Access Data in Nested Structures
- •Access Elements of a Nonscalar Struct Array
- •Create a Cell Array
- •Access Data in a Cell Array
- •Add Cells to a Cell Array
- •Delete Data from a Cell Array
- •Combine Cell Arrays
- •Pass Contents of Cell Arrays to Functions
- •Multilevel Indexing to Access Parts of Cells
- •Related Examples
- •What Is a Function Handle?
- •Creating a Function Handle
- •Maximum Length of a Function Name
- •The Role of Scope, Precedence, and Overloading When Creating a Function Handle
- •Obtaining Permissions from Class Methods
- •Example
- •Using Function Handles for Anonymous Functions
- •Arrays of Function Handles
- •Calling a Function Using Its Handle
- •Calling Syntax
- •Calling a Function with Multiple Outputs
- •Returning a Handle for Use Outside of a Function File
- •Example — Using Function Handles in Optimization
- •Preserving Data from the Workspace
- •Preserving Data with Anonymous Functions
- •Preserving Data with Nested Functions
- •Loading a Saved Handle to a Nested Function
- •Applications of Function Handles
- •Example of Passing a Function Handle
- •Pass a Function to Another Function
- •Example 1 — Run integral on Varying Functions
- •Example 2 — Run integral on Anonymous Functions
- •Example 3 — Compare integral Results on Different Functions
- •Capture Data Values For Later Use By a Function
- •Example 1 — Constructing a Function Handle that Preserves Its Variables
- •Example 2 — Varying Data Values Stored in a Function Handle
- •Example 3 — You Cannot Vary Data in a Handle to an Anonymous Function
- •Call Functions Outside of Their Normal Scope
- •Save the Handle in a mat-File for Use in a Later matlab Session
- •Parameterizing Functions
- •Overview
- •Parameterizing Using Nested Functions
- •Parameterizing Using Anonymous Functions
- •See Also
- •More About
- •Saving and Loading Function Handles
- •Invalid or Obsolete Function Handles
- •Advanced Operations on Function Handles
- •Examining a Function Handle
- •Converting to and from a String
- •Converting a String to a Function Handle
- •Converting a Function Handle to a String
- •Comparing Function Handles
- •Comparing Handles Constructed from a Named Function
- •Comparing Handles to Anonymous Functions
- •Comparing Handles to Nested Functions
- •Comparing Handles Saved to a mat-File
- •Overview of the Map Data Structure
- •Description of the Map Class
- •Properties of the Map Class
- •Methods of the Map Class
- •Creating a Map Object
- •Constructing an Empty Map Object
- •Constructing An Initialized Map Object
- •Combining Map Objects
- •Examining the Contents of the Map
- •Reading and Writing Using a Key Index
- •Reading From the Map
- •Adding Key/Value Pairs
- •Building a Map with Concatenation
- •Modifying Keys and Values in Map
- •Removing Keys and Values from the Map
- •Modifying Values
- •Modifying Keys
- •Modifying a Copy of the Map
- •Mapping to Different Value Types
- •Mapping to a Structure Array
- •Mapping to a Cell Array
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.