LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching a truth table with 3 inputs then printing the output

Hi! I am trying to code a program that takes a truth table as an input then searches each row for a specified input signal combination.

 

For examle if I search for the combination x1=1, x2=0, x3=1 then this program should find a matching row then print the output that this row produces. The output is also specified in a table. 

 

The code I have made does not work because when I use the "search 1D array" function it jumps directly to the searched input instead of itterating each row from index 0. This is easier to understand by looking at the code. My question is, how can I change the code so that the truth table is searched from the start and stops when the searched value is found on the same row?

0 Kudos
Message 1 of 4
(637 Views)

Can you do a "save for previous" before attaching. Many don't have access to LabVIEW 2021 yet. (Or (only if the code is very simple and nothing is hidden!!!), attach a picture at least)

0 Kudos
Message 2 of 4
(615 Views)

@GG00 wrote:

Hi! I am trying to code a program that takes a truth table as an input then searches each row for a specified input signal combination.

 

For examle if I search for the combination x1=1, x2=0, x3=1 then this program should find a matching row then print the output that this row produces. The output is also specified in a table. 

 

 


This makes very little sense to me as a "truth table" sets out the functional values of logical expressions. The output of a truth table is dependent on the logic the truth table is showing.

 

So lets stop calling it a "truth table" and just call it an array.

 

DO you want to search a 2D array row by row to match the first two elements, then return the third element in the matching row?

 

How about something like this?

 

SearchArray.png

 

Match not found returns NaN (Not a Number)

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 4
(599 Views)

I also can't open your VI, and I'm also a bit a confused by your statement that you take "a truth table" as an input, but it kind of sounds like what you are trying to do is implement a lookup table.

 

You could do this with arrays and/or case structures, but, since you are using a version of LabVIEW newer than 2019, I'd recommend looking into maps. Your inputs would be the key,your expected output the value. That's assuming you have a fairly finite set of inputs and can reasonably just create a map constant for them. (Assuming your x1-x3 values are actually meant to represent booleans since you only mentioned 0 and 1 values for them, you should only need 8 entries at most.)

 

Of course, it would help to understand more precisely what you are trying to do. If your output could be dynamically generated from the inputs, then there could be more elegant solutions.

0 Kudos
Message 4 of 4
(567 Views)