not, ~
计算逻辑 NOT
说明
示例
矩阵的逻辑求反
创建一个 3×3 单位矩阵。
A = eye(3)
A = 3×3
1 0 0
0 1 0
0 0 1
对 A
进行逻辑求反。新矩阵的类型为 logical
。
B = ~A
B = 3x3 logical array
0 1 1
1 0 1
1 1 0
执行条件代码
在 if
循环的上下文使用逻辑 not 运算符基于条件执行代码。
创建逻辑变量 A
。
A = false;
使用 A
编写 if/else 代码块。将 if/else 代码块放入 for
循环中,使其执行四次。
for k = 1:4 if ~A disp('IF block') A = true; else disp('ELSE block') end end
IF block
ELSE block ELSE block ELSE block
在第一次迭代时,A
为 false
,所以 ~A
为 true
,因此 if
块执行。但是,if
块还将 A
的值更改为 true
。在剩余迭代中,~A
为 false
,所以 else
块执行。
表的逻辑 NOT
自 R2023a 开始提供
创建一个表并对其执行逻辑 NOT 运算。要对表或时间表执行逻辑 NOT 运算,其所有变量都必须具有支持逻辑运算的数据类型。
A = table([0;2],[0;4],VariableNames=["V1","V2"],RowNames=["R1","R2"])
A=2×2 table
V1 V2
__ __
R1 0 0
R2 2 4
~A
ans=2×2 table
V1 V2
_____ _____
R1 true true
R2 false false
输入参数
A
— 输入数组
标量 | 向量 | 矩阵 | 多维数组 | 表 | 时间表
输入数组,指定为数值标量、向量、矩阵、多维数组、表或时间表。
数据类型: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| char
| table
| timetable
复数支持: 是
提示
您还可以使用
~
符号作为函数调用中的占位符输出参数。例如,[~,i] = max(A)
隐藏max
函数的第一个输出,只返回最大值的索引。有关详细信息,请参阅忽略函数定义中的输入。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
此函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
GPU 代码生成
使用 GPU Coder™ 为 NVIDIA® GPU 生成 CUDA® 代码。
HDL 代码生成
使用 HDL Coder™ 为 FPGA 和 ASIC 设计生成 VHDL、Verilog 和 SystemVerilog 代码。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
GPU 数组
通过使用 Parallel Computing Toolbox™ 在图形处理单元 (GPU) 上运行来加快代码执行。
此函数完全支持 GPU 数组。有关详细信息,请参阅Run MATLAB Functions on a GPU (Parallel Computing Toolbox)。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2006a 之前推出R2023a: 直接对表和时间表执行运算
not
运算符支持直接对表和时间表执行运算,无效通过索引访问其变量。所有变量都必须具有支持该运算的数据类型。有关详细信息,请参阅Direct Calculations on Tables and Timetables。
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)