Example Code

Lookup Table Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
This VI illustrates how to perform a lookup from a table of data saved in a spreadsheet file.

 
Description

Many applications rely on making a lookup to a table to extract pertinent data. Such tables are commonly saved in spreadsheets and have .CSV or .XLS (Excel) file extensions. This VI uses data composed of 3 different parameters, located in a .CSV file. The user can perform a lookup with 1 or 2 parameters. The goal of this VI is to illustrate the key components of a lookup system, such that more complex lookups can be derived from learning from this VI.

A few key things to note about this lookup program:

  1. The program doesn't implement any type of interpolation between entries in the table. This behavior is often required/useful, and can be implemented with modifications to this basic program
  2. In lieu of interpolation, some applications require that a lookup return the closest match in the table. Again, such behavior is not built into this program, but can be added with some modifications.


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Select the Physical Channel
  2. Open the LUT.vi, and specify the file path of 'LUT File' to the .CSV file that you just downloaded (LUT.csv). You may also have to manually point LabVIEW to the location of IndexMatching.vi, which is a dependency of LUT.vi.
  3. Run LUT.vi. You will see that the data from the LUT.csv file is displayed on the front panel. You can select which parameters you want to use for a lookup and specify values for them. Note that parameter 1 is a string type, and that the other two parameters are a numeric type. The program will perform the lookup. If you over-specify the lookup, choose no parameters with which to perform a lookup, or enter values for parameters which don't match anything in the table, the lookup will return a null result.
  4. Stop the program and investigate the block diagram, which is heavily commented to describe the implementation logic.

 

Additional Information or References
VI Snippet

004.png

**This document has been updated to meet the current required format for the NI Code Exchange.**

Sanjay C.
Embedded Software Product Manager| National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
yin_the_novice
Member
Member
on

Thanks for uploading these useful files. I downloaded them and my excitement built up as I started to open up LUT.vi  only to suffer bitter disappointment when I couldn't open it because it was in LV 2010.   Any chance you could upload additional copies in 2009 or earlier version.

Thank You

Sanjay_C.
NI Employee (retired)
on

Hi Yin,

I have attached another ZIP file named LUT_80.zip which contains all the VIs in LabVIEW 8.0. Let me know if you still aren't able to access the code.

Sanjay C.
Embedded Software Product Manager| National Instruments
yin_the_novice
Member
Member
on

thanks for the upload Sanjay !

Yin

1984
Active Participant
Active Participant
on

I have found a bug:

In the orignal LUT file there are multiple entries with 20 at param3. If in the lookup cluster I select param3 only and type 20 then all of them are listed. If modify the LUT file to create entries where param2 AND param3 are also the same (like A 0 1, B 0 1) then the following happens:

1. if I select only param2 (0) >>> all entries where param2 = 0 are listed

2. if I select only param3 (1) >>> all entries where param3 = 1 are listed

3. if I select both param2 (0) and param3 (1) then the Result is empty

I have not spent time to debug the code, but however this is a severe problem I guess probably it would be an easy fix.

1984
Active Participant
Active Participant
on

I have created another version. I have no clue how to attach a file, so I attach a screenshot.

1. I have found better if we handle all the params as strings since the file read converts everything to string anyways

2. From my perspective if none of checkboxes are checked then the result should be equal to the LUT. This can be disputed of course, but if you want that feature just add an extra case around the for structure

3. The false case just drives the shift register of the for structure to the output tunnel

If you create the params and the checkboxes as arrays then this is a really scalable solution. (I hope its bug free)

LUTcheck.gif

dfp
Member
Member
on

There was a mis-wiring that prevented LUT.vi from finding table entries when only parameters 2 and 3 were selected for use.  The inner most case structure in step 3 was wired to the arrays associated with parameters 1 and 3 instead of parameters 2 and 3.

Tariff Impact Update Learn more