主要内容

le,<=

确定少于或等于

Syntax

描述

example

A<=Breturns a logical array with elements set to logical 1 (真的) whereAis less than or equal toB; otherwise, the element is logical0(false). The test compares only the real part of numeric arrays.lereturns logical0(false) whereA或者B有nan或不确定分类elements.

le(A,B)是执行的另一种方法a <= b, but is rarely used. It enables operator overloading for classes.

例子

全部收缩

Find which vector elements are less than or equal to a given value.

Create a numeric vector.

a = [1 12 18 7 9 11 2 15];

测试向量的元素小于或等于12.

a <= 12
ans =1x8 logical array1 1 0 1 1 1 1 0

The result is a vector with values of logical1(真的)元素Asatisfy the expression.

使用逻辑值向量作为索引来查看值Athat are less than or equal to12.

A(A <= 12)
ans =1×61 12 7 9 11 2

结果是元素的子集A.

Create a matrix.

a =魔术(4)
A =4×416 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1

替换所有小于或等于的值9带有值10.

A(A <= 9) = 10
A =4×416 10 10 13 10 11 10 10 10 10 10 12 10 14 15 10

结果是一个新矩阵,其最小元素是10.

创建一个顺序的分类阵列。

a =分类({'大的''medium''小的';'medium'...'小的''大的'},{'小的''medium''大的'},,“序数”,1)
A =2x3 categoricallarge medium small medium small large

The array has three categories:'小的','medium', 和'大的'.

Find all values less than or equal to the category'medium'.

a <='medium'
ans =2x3 logical array0 1 1 1 1 0

A value of logical1(真的) indicates a value less than or equal to the category'medium'.

Compare the rows ofA.

a(1,:) <= a(2,:)
ans =1x3逻辑数组0 0 1

该功能返回逻辑1(真的) where the first row has a category value less than or equal to the second row.

Create a vector of complex numbers.

a = [1+i 2-2i 1+3i 1-2i 5-i];

Find the values that are less than or equal to3.

A(a <= 3)
ans =1×4 complex1.0000 + 1.0000i 2.0000 - 2.0000i 1.0000 + 3.0000i 1.0000 - 2.0000i

lecompares only the real part of the elements inA.

利用absto find which elements are within a radius of3from the origin.

A(abs(A) <= 3)
ans =1×3 complex1.0000 + 1.0000i 2.0000 - 2.0000i 1.0000 - 2.0000i

The result has one less element. The element1.0000 + 3.0000i不在半径内3from the origin.

Create aduration大批。

d =hours(21:25) + minutes(75)
d =1x5持续时间22.25 HR 23.25 HR 24.25 HR 25.25 HR 26.25 HR

测试阵列的小于或等于一个标准日的元素。

D <= 1
ans =1x5逻辑数组1 1 0 0 0

输入参数

全部收缩

操作数,指定为标量,向量,矩阵或多维阵列。输入ABmust either be the same size or have sizes that are compatible (for example,A是一个M-经过-N矩阵和B是标量或1-经过-N行矢量)。有关更多信息,请参阅兼容阵列大小用于基本操作.

您可以比较任何类型的数字输入,并且该比较不会因类型转换而损失精度。

  • 如果一个输入是序数分类数组,另一个输入可以是序数分类array, a cell array of character vectors, or a single character vector. A single character vector expands into a cell array of character vectors of the same size as the other input. If both inputs are ordinal分类数组, they must have the same sets of categories, including their order. SeeCompare Categorical Array Elements更多细节。

  • 如果一个输入是约会时间array, the other input can be a约会时间数组,字符向量或字符向量的单元格数组。

  • 如果一个输入是durationarray, the other input can be adurationarray or a numeric array. The operator treats each numeric value as a number of standard 24-hour days.

  • 如果一个输入是字符串数组,则另一个输入可以是字符串数组,字符向量或字符向量的单元格数组。相应的元素AB在词典上进行比较。

数据类型:single|双倍的|int8|INT16|INT32|INT64|uint8|UINT16|uint32|uint64|logical|char|string|分类|约会时间|duration
Complex Number Support:Yes

提示

兼容性考虑

展开全部

Behavior changed in R2016b

R2020b中的行为发生了变化

Extended Capabilities

C/C ++代码生成
使用MATLAB®CODER™生成C和C ++代码。

GPU Code Generation
使用GPU CODER™为NVIDIA®GPU生成CUDA®代码。

HDL代码生成
使用HDL Coder™生成用于FPGA和ASIC设计的Verilog和VHDL代码。

在R2006a之前引入