主要内容

MATLAB操作员和特殊角色

此页面包含所有MATLAB的全面列表®操作员,符号和特殊字符。

算术操作员

Symbol 角色 更多信息
+

一个ddition

plus
+

Unary Plus

Uplus
-

Subtraction

minus
-

单位减

Uminus
。*

元素乘法

times
*

矩阵乘法

mtimes
。/

元素右部门

rdivide
/

矩阵右部门

mrdivide
。\ \

元素左派

ldivide
\ \

矩阵左师

(also known as后斜线

mldivide
。^

元素能力

力量
^

矩阵功率

马力
。'

转置

transpose
'

复杂的共轭转置

CTRANSPOSE

Relational Operators

Symbol 角色 更多信息
==

Equal to

等式
〜=

not equal to

ne
>

Greater than

GT
> =

大于或等于

GE
<

Less than

lt
<=

小于或等于

le

逻辑操作员

Symbol 角色 更多信息

Find logical AND

and
|

找到逻辑或

or
&&

Find logical AND (with short-circuiting)

逻辑运算符:短路&& ||
||

找到逻辑或(with short-circuiting)

找不到逻辑

不是

特殊字符

@

name:一个t symbol

用途

  • 功能处理构造和参考

  • Calling superclass methods

描述: 这@符号为遵循的命名函数形成句柄@签名,或符合遵循的匿名函数@sign. You can also use@从子类调用超类方法。

例子

创建一个命名函数的函数句柄:

fhandle = @myfun

为匿名函数创建函数句柄:

fhandle = @(x,y)x。^2 + y。^2;

致电disp的方法MySuper来自子类:

disp@mysuper(obj)

使用要构造的对象从子类调用超类构造函数:

obj = obj@mysuper(arg1,arg2,。。。

更多信息

name:期间或点

用途

  • Decimal point

  • Element-wise operations

  • 结构字段访问

  • Object property or method specifier

描述: 这period character separates the integral and fractional parts of a number, such as3.1415。包含一个周期的MATLAB操作员始终在工作元素方面。周期字符还使您可以访问结构中的字段以及对象的属性和方法。

例子

小数点:

102.5543

元素操作:

A.*B A.^2

结构字段访问:

mystruct.f1

对象属性规范:

myobj.propertyname

更多信息

。。。

name:点点或省略号

用途:Line continuation

描述:Three or more periods at the end of a line continues the current command on the next line. If three or more periods occur before the end of a line, then MATLAB ignores the rest of the line and continues to the next line. This effectively makes a comment out of anything on the current line that follows the three periods.

笔记

Matlab将省略号解释为空间特征。因此,多行命令必须有效作为单行,其省略号被空间字符代替。

例子

继续在下一行上进行函数调用:

sprintf(['这current value '。。。'%s是%d'],vname,value)

将角色向量分解在多条线上,并将线路连接在一起:

s = ['如果在'之前发生三个或以上的时间。。。'结尾of a line, then the rest of that line is '。。。“被忽略,Matlab继续进入下一行”这是给予的

要在多行命令中评论一行,请使用。。。在行的开头,以确保命令保持完整。如果您使用评论一条线会产生错误:

y = 1 +。。。2 +。。。%3 +...4;

However, this code runs properly since the third line does not produce a gap in the command:

y = 1 +。。。2 +。。。。。。3 +...4;

更多信息

,,,,

name:Comma

用途:Separator

描述:Use commas to separate row elements in an array, array subscripts, function input and output arguments, and commands entered on the same line.

例子

单独的行元素以创建一个数组:

一个=[12,13; 14,15]

Separate subscripts:

A(1,2)

功能调用中的单独输入和输出参数:

[Y,I] = max(A,[],2)

Separate multiple commands on the same line (showing output):

图,情节(sin(-pi:0.1:pi)),网格on

更多信息

name: 冒号

用途

  • 向量创建

  • 索引

  • 循环迭代

描述:使用结肠操作员创建定期间隔的向量,索引到数组,并定义一个的边界为了环形。

例子

创建一个向量:

x = 1:10

创建一个向量增加3:

x = 1:3:19

将矩阵重塑为列向量:

一个(:)

分配新元素而不更改数组的形状:

a = rand(3,4);A(:) = 1:12;

在特定维度中索引一系列元素:

A(2:5,3)

索引特定维度中的所有元素:

A(:,3)

为了loop bounds:

x = 1;为了k = 1:25 x = x + x^2;结尾

更多信息

;

name:Semicolon

用途

  • 表示行的结尾

  • 抑制代码线的输出

描述:使用分号在数组创建命令中分离行,或抑制代码行的输出显示。

例子

单独的行创建一个数组:

一个=[12,13; 14,15]

Suppress code output:

y = max(a);

单个行上的单独多个命令(抑制输出):

a = 12.5;B = 42.7,C = 1.25;B = 42.7000

更多信息

( )

name: 括号

用途

  • 操作员优先

  • 功能参数外壳

  • 索引

描述:Use parentheses to specify precedence of operations, enclose function input arguments, and index into an array.

例子

行动的优先级:

(A B C D

功能参数外壳:

plot(X,Y,'r*')c =联合(a,b)

索引:

A(3,:) a(1,2)a(1:5,1)

更多信息

[ ]

name: 方括号

用途

  • 阵列构造

  • 一个rray concatenation

  • 空矩阵和数组元素删除

  • 多输出参数分配

描述:方括号启用数组构造和串联,创建空矩阵,删除数组元素以及捕获函数返回的值。

例子

Construct a three-element vector:

X = [10 12 -3]

向矩阵添加新的底部行:

a = rand(3);a = [a;10 20 30]

创建一个空矩阵:

一个=[]

删除矩阵列:

A(:,1)= []

Capture three output arguments from a function:

[c,ia,ib] =联合(a,b)

更多信息

{ }

name: 大括号

用途:单元阵列分配和内容

描述:使用卷曲括号构造单元格数,或访问单元格数组中特定单元格的内容。

例子

要构造一个单元格数组,将数组的所有元素包装在卷曲括号中:

c = {[2.6 4.7 3.9],rand(8)*6,'C。柯立芝'}

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

一个=C{4,7,2}

更多信息

name: 百分

用途

  • Comment

  • 转换说明符

描述: 这percent sign is most commonly used to indicate nonexecutable text within the body of a program. This text is normally used to include comments in your code.

某些功能还将百分比符号解释为转换说明符。

2%的迹象,%%,作为一个细胞定界符,如在代码中创建和运行部分

例子

将注释添加到一个代码块中:

%循环的目的是计算% 的价值 ...

Use conversion specifier withSprintf

sprintf('%s =%d',,,,name, value)

更多信息

%{%}

name:百分比卷曲支架

用途:block comments

描述: 这%{and%}符号包围了一系列评论,这些评论超出了一行。

笔记

With the exception of whitespace characters, the%{and%}操作员必须独自出现在紧接的线路上并遵循帮助文本的块。不要在这些行上包含任何其他文本。

例子

Enclose any multiline comments with percent followed by an opening or closing brace:

%{此例程的目的是计算的价值 ...%}

更多信息

name:感叹号

用途:操作系统命令

描述:在MATLAB内部执行的操作系统命令之前的感叹点要先于操作系统命令。

not available inMATLABOnline™

例子

这exclamation point initiates a shell escape function. Such a function is to be performed directly by the operating system:

!rmdir oldtests

更多信息

name:问号

用途:matlab课程的元类

描述: 这question mark retrieves theobject for a particular class name. The操作员仅使用类名称,而不是对象。

例子

检索类的meta.class对象InputParser

?inputparser

更多信息

''

name:Single quotes

用途:字符阵列构造函数

描述:Use single quotes to create character vectors that have classchar

例子

创建一个字符向量:

chr ='你好世界'

更多信息

“”

name: 双引号

用途:String constructor

描述:使用双引号创建具有类的字符串标量细绳

例子

创建一个字符串标量:

s =“你好世界”

更多信息

N/A。

name:太空角色

用途:Separator

描述:Use the space character to separate row elements in an array constructor, or the values returned by a function. In these contexts, the space character and comma are equivalent.

例子

单独的行元素以创建一个数组:

这些陈述是等效的a = [12 13;14 15] a = [12,13;14,15]

Separate output arguments in function calls:

这些陈述是等效的[y i] = max(a)[y,i] = max(a)
N/A。

name:newline字符

用途:Separator

描述:Use the newline character to separate rows in an array construction statement. In that context, the newline character and semicolon are equivalent.

例子

数组创建命令中的单独行:

这些陈述是等效的一个=[12 13 14 15] A = [12 13; 14 15]

name:tilde

用途

  • 逻辑不是

  • 争论占位符

描述:Use the tilde symbol to represent logical NOT or to suppress specific input or output arguments.

例子

计算矩阵的逻辑:

a =眼(3);〜a

确定元素的位置一个are not equal to those ofb

a = [1 -1;0 1] b = [1 -2;3 2] a〜 = b

仅返回第三个输出值的联盟

[~, ~, iB] =联盟(A, B)

更多信息

=

name:平等标志

用途: 任务

描述:使用平等符号将值分配给变量。语法b = astores the elements of一个在变量中b

笔记

=角色是为分配的,而==字符用于比较两个数组中的元素。看等式了解更多信息。

例子

Create a matrix一个。一个ssign the values in一个到一个新变量,b。Lastly, assign a new value to the first element inb

一个=[1 0; -1 0]; B = A; B(1) = 200;
<&

name:左角支架和兼而

用途:Specify superclasses

描述:Specify one or more superclasses in a class definition

例子

定义从一个超级类派生的类:

ClassDefmy级结尾

Define a class that derives from multiple superclasses:

ClassDefMyClass < Superclass1 & Superclass2 & … …结尾

更多信息

。?

name:Dot question mark

用途:指定名称值结构的字段

描述

使用函数参数验证时,您可以将名称值结构的字段定义为类的所有可写入属性的名称。

例子

指定字段名称propArgs结构作为可写的特性matlab.graphics.primitive.line班级。

functionf(propArgs)参数propargs结尾%功能代码。。。结尾

更多信息

String and Character Formatting

一些特殊字符只能在字符向量或字符串的文本中使用。您可以使用这些特殊字符插入新线路或运输返回,指定文件夹路径等。

使用此表中的特殊字符使用字符向量或字符串指定文件夹路径。

/

\ \

name:Slash and Backslash

用途:File or folder path separation

描述:除了用作数学运算符外,斜线和背斜线字符还将路径或文件夹的元素分开。在Microsoft上®Windows®基于系统,斜线和后斜线都具有相同的效果。在开放式unix上®based systems, you must use slash only.

例子

在Windows系统上,您可以使用BackSlash或Slash:

dir([matlabroot'\ toolbox \ matlab \ elmat \ shiftdim.m'])dir([Matlabroot'/toolbox/matlab/elmat/shiftdim.m')))

在UNIX系统上,仅使用前向斜线:

dir([matlabroot'/toolbox/matlab/elmat/shiftdim.m')))

。。

name:点点

用途:父文件夹

描述:连续两个点是指当前文件夹的父。使用此字符来指定相对于当前文件夹的文件夹路径。

例子

要在文件夹树中上升两个级别,然后向下进入测试folder, use:

光盘..\..\测试

更多信息

*

name:星号

用途:Wildcard character

描述:除了是矩阵乘法的符号外,星号*被用作通配符。

通配符通常用于对多个文件或文件夹作用的文件操作。MATLAB与名称中的所有字符完全匹配,除了通配符字符*,可以匹配任何一个或多个字符。

例子

找到所有以开头的名称的文件january_并有一个。matfile extension:

dir('1月_*。垫子'

@

name:一个t symbol

用途:Class folder indicator

描述:一个n@符号指示类文件夹的名称。

例子

请参阅类文件夹:

\ \@myClass\get.m

更多信息

+

name:plus

用途:软件包目录指示器

描述:一个+符号指示包装文件夹的名称。

例子

Package folders always begin with the+特点:

+mypack +mypack/pkfcn.m%包装功能+mypack/@myclass包装中的%类文件夹

更多信息

有某些特殊字符,您无法作为普通文本输入。相反,您必须使用唯一的字符序列来表示它们。使用此表中的符号自行格式化字符串和角色向量,或与格式函数(如撰写,,,,Sprintf,,,,and错误。For more information, see格式化文本

Symbol Effect on Text
''

单引号标记

%%

单个百分比符号

\\

单个后斜线

\一个

一个larm

\ b

backspace

\F

形式饲料

\ n

新队

\ r

Carriage return

\ t

水平标签

\ v

垂直选项卡

\ xn

Hexadecimal number,n

\ n

八达数字,n

Related Topics