Documentation

真的

Logical 1 (true)

Description

example

真的is shorthand for the logical value1.

example

T= true(n)is ann-by-nmatrix of logical ones.

example

T= true(sz)is an array of logical ones where the size vector,sz, defines尺寸(t). For example,真的([2 3])returns a 2-by-3 array of logical ones.

example

T= true(sz1,...,szN)is asz1-by-...-by-szNarray of logical ones wheresz1,...,szNindicates the size of each dimension. For example,真的(2,3)returns a 2-by-3 array of logical ones.

example

T= true(___,'喜欢',p)返回与逻辑变量相同稀疏的一系列逻辑上的数组pusing any of the previous size syntaxes.

Examples

collapse all

Use真的生成一个逻辑上的3 x平方矩阵。

A = true(3)
A =3x3 logical array1 1 1 1 1 1 1 1 1 1
class(A)
ans = 'logical'

结果是课堂logical.

Use真的生成一个逻辑上的3 by-2-by-2矩阵。

真的(3,2,2)
ans =3x2x2 logical arrayans(:,:,1) = 1 1 1 1 1 1 ans(:,:,2) = 1 1 1 1 1 1

Alternatively, you can use a size vector to specify the size of the matrix.

真的([3,2,2])
ans =3x2x2 logical arrayans(:,:,1) = 1 1 1 1 1 1 ans(:,:,2) = 1 1 1 1 1 1

Note that specifying multiple vector inputs returns an error.

真的along withfalse可用于执行逻辑语句。

Test the logical statement

~(A and B) = (~A) or (~B)

forA = trueB = false.

~(true & false) == (~true) | (~false)
ans =logical1

结果是逻辑1(true),因为方程式两侧的逻辑语句是等效的。这种逻辑陈述是德·摩根定律的一个实例。

生成与所选数组相同的稀疏性的逻辑数组。

A = logical(sparse(5,3)); whosA
Name Size Bytes Class Attributes A 5x3 41 logical sparse
T = true(4,'like',A); whosT
名称大小字节类属性t 4x4 184逻辑稀疏

输出数组Thas the samesparse一个属性nd data-type as the specified arrayA.

Input Arguments

collapse all

Size of square matrix, specified as an integer.n将输出数组大小设置为n-by-n. For example,真的(3)returns a 3-by-3 array of logical ones.

  • Ifnis0, thenTis an empty matrix.

  • Ifn是负面的,然后被视为0.

Data Types:int8|INT16|int32|int64|uint8|uint16|uint32|uint64

Size vector, specified as a row vector of integers. For example,真的([2 3])returns a 2-by-3 array of logical ones.

  • If the size of any dimension is0, thenTis an empty array.

  • If the size of any dimension is negative, then it is treated as0.

  • If any trailing dimensions greater than2have a size of1,然后输出,T,不包括这些维度。

Data Types:int8|INT16|int32|int64|uint8|uint16|uint32|uint64

Size inputs, specified by a comma-separated list of integers. For example,真的(2,3)returns a 2-by-3 array of logical ones.

  • If the size of any dimension is0, thenTis an empty array.

  • If the size of any dimension is negative, then it is treated as0.

  • If any trailing dimensions greater than2have a size of1,然后输出,T,不包括这些维度。

Data Types:int8|INT16|int32|int64|uint8|uint16|uint32|uint64

Prototype, specified as a logical variable.

Data Types:single|double|int8|INT16|int32|int64|uint8|uint16|uint32|uint64
Complex Number Support:Yes

Output Arguments

collapse all

Output of logical ones, returned as a scalar, vector, matrix, or N-D array.

Data Types:logical

Tips

  • 真的(n)is much faster and more memory efficient thanlogical(true(n)).

Extended Capabilities

在R2006a之前引入