not - Find logical NOT - MATLAB (original) (raw)

Syntax

Description

~[A](#bu3um2z-A) returns a logical array or a table of logical values of the same size as A. The output contains logical 1 (true) values whereA is zero and logical 0 (false) values where A is nonzero.

example

not([A](#bu3um2z-A)) is an alternate way to execute ~A, but is rarely used. It enables operator overloading for classes.

Examples

collapse all

Logical Negation of Matrix

Create a 3-by-3 identity matrix.

A = 3×3

 1     0     0
 0     1     0
 0     0     1

Find the logical negation of A. The new matrix has type logical.

B = 3x3 logical array

0 1 1 1 0 1 1 1 0

Conditional Code Execution

Execute code based on a condition using the logical not operator in the context of an if loop.

Create a logical variable A.

Use A to write an if/else code block. Wrap the if/else block in a for loop so that it executes four times.

for k = 1:4 if ~A disp('IF block') A = true; else disp('ELSE block') end end

ELSE block ELSE block ELSE block

On the first iteration, A is false, so the if block executes since ~A is true. However, the if block also changes the value of A to true. In the remaining iterations, ~A is false and the else block executes.

Logical NOT of Table

Since R2023a

Create a table and perform a logical NOT of it. To perform a logical NOT of a table or timetable, all its variables must have data types that support logical operations.

A = table([0;2],[0;4],VariableNames=["V1","V2"],RowNames=["R1","R2"])

A=2×2 table V1 V2 __ __

R1    0     0 
R2    2     4 

ans=2×2 table V1 V2
_____ _____

R1    true     true 
R2    false    false

Input Arguments

collapse all

A — Input array

scalar | vector | matrix | multidimensional array | table | timetable

Input array, specified as a numeric scalar, vector, matrix, multidimensional array, table, or timetable.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | table | timetable
Complex Number Support: Yes

Tips

Extended Capabilities

Tall Arrays

Calculate with arrays that have more rows than fit in memory.

Thenot function fully supports tall arrays. For more information, see Tall Arrays.

C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation

Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

HDL Code Generation

Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Thread-Based Environment

Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

GPU Arrays

Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

The not function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Distributed Arrays

Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.

This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).

Version History

Introduced before R2006a

expand all

R2023a: Perform operations directly on tables and timetables

The not operator supports operations directly on tables and timetables without indexing to access their variables. All variables must have data types that support the operation. For more information, see Direct Calculations on Tables and Timetables.