Find logical NOT
Logical Negation of Matrix
Create a 3-by-3 identity matrix.
A = eye(3)
A = 3×3 1 0 0 0 1 0 0 0 1
Find the logical negation of
A. The new matrix has type
B = ~A
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
Create a logical variable
A = false;
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,
false, so the
if block executes since
true. However, the
if block also changes the value of
true. In the remaining iterations,
false and the
else block executes.
A — Input array
scalar | vector | matrix | multidimensional array
Input array, specified as a numeric scalar, vector, matrix, or multidimensional array.
Complex Number Support: Yes
You also can use the
~symbol as a placeholder output argument in a function call. For example,
[~,i] = max(A)suppresses the first output of the
maxfunction, returning only the indices of the maximum values. For more information, see Ignore Inputs in Function Definitions.
Calculate with arrays that have more rows than fit in memory.
This 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 Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
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).