添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
时尚的砖头  ·  ischange·  19 小时前    · 
从容的圣诞树  ·  MySQL-17-mysql alter ...·  昨天    · 
英俊的大葱  ·  js-table-print CDN by ...·  昨天    · 
仗义的火车  ·  Meteor 1.6.x + Ant ...·  昨天    · 
冷静的抽屉  ·  Women's Big Bash ...·  昨天    · 
俊逸的斑马  ·  Update 4 for Inventor ...·  1 月前    · 
淡定的水煮肉  ·  Exception of ...·  6 月前    · 
越狱的鼠标  ·  标签组件 | Midway·  10 月前    · 

not , ~

Find logical NOT

collapse all in page

Description

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

example

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

Examples

collapse all

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 logical .

B = ~A
B = 3x3 logical array
   0   1   1
   1   0   1
   1   1   0

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

Create a logical variable A .

A = false;

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;
        disp('ELSE block')
end
IF block
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.

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 
~A
ans=2×2 table
           V1       V2  
          _____    _____
    R1    true     true 
    R2    false    false

Input Arguments

collapse all

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

  • 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 max function, returning only the indices of the maximum values. For more information about suppressing function arguments, see Ignore Inputs in Function Definitions and Ignore Function Outputs .

Extended Capabilities

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™.

Version History

Introduced before R2006a

expand all

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.