01-17-2024 02:16 AM
Hi,
is there any function in labview that negates the input signal (0 to 1)? Thanks for help.
Solved! Go to Solution.
01-17-2024 02:28 AM - edited 01-17-2024 02:37 AM
There is a function that negates an input, called Negate, it can be found among Numeric functions, but you'd get a result of -1 if you input 1.
What you are describing is more of a boolean negation, in which case you have a Not function among Boolean functions. If you insist on using numbers for this then transform to boolean, negate and then transform back.
I don't think there is a single function that does this for numbers tho.
EDIT:
3 ways to do it
They all output the same, if you only use 0 and 1.
01-17-2024 02:33 AM - edited 01-17-2024 02:46 AM
Hi Tim,
You may want to convert your signal to boolean first by using one of the comparison functions (e.g. "Equal To 0?", which implicitly negates the value), then use "Boolean to (0, 1)" to convert it back to Integer:
What is the input and output signal data type ? Integer ? Boolean ?
Regards,
Raphaël.
01-17-2024 02:36 AM
Thanks, now it works.
Best regards,
Tim
01-17-2024 07:09 AM
01-17-2024 07:43 AM
@GerdW wrote:
What about this:
y := 1 - x
I was thinking to add 1 and then AND with 1. But yours is simpler still.
x = (x+1) && 1
01-17-2024 07:56 AM
With an integer type, you could also just XOR with 1. That'll transform 0-->1 and 1-->0.
-Kevin P
01-17-2024 08:52 AM - edited 01-17-2024 09:45 AM
@crossrulz wrote:
@GerdW wrote:
What about this:
y := 1 - x
I was thinking to add 1 and then AND with 1. But yours is simpler still.
x = (x+1) && 1
There might be a programming language where && is a binary AND but generally in the languages I know you would need to use & here since && is a logical AND.
For x = 1, our expression evaluates to:
x = 2 && 1
and in C (and C++, C#, Java and likely several others) this would still be true (1) since any value other than 0 is normally treated as true (1) when evaluating values as logical value.
Even Pascal/Modula (because of the original := assignment operator in the post you responded to) uses the single & and | as binary operator, but "and" and "or" as logical operator.
The LabVIEW Boolean operator nodes perform automatically a binary operation on integers and only a logical operation on Booleans. This is because in LabVIEW the Boolean data type is a first class element. In C and most C influenced languages Boolean was originally NOT an existing data type and instead an integer was used to emulate Booleans. Only later dialects of C introduced an explicit Boolean datatype but backwards compatibility required it to still work like earlier versions.
01-17-2024 01:08 PM
@rolfk wrote:There might be a programming language where && is a binary AND but generally in the languages I know you would need to use & here since && is a logical AND.
Yep, you caught me. I need to get back into playing with my Pi Pico to dust off many layers of C rust.
01-17-2024 07:01 PM - edited 01-17-2024 07:05 PM
@Tim970 wrote:
is there any function in labview that negates the input signal (0 to 1)? Thanks for help.
Obviously we need to know the datatype (integer? DBL? scalar? array? etc.). Where does the signal come from? (if it is from a digital input, it might already be boolean and if it is from an analog input, it might be close, bun not exactly zero or one)
Can you guarantee that the input is never outside the range 0..1? If not, what should happen if the input is invalid?
If it can never be outside 0..1, maybe a boolean datatype would be a better choice to carry along?