Example Program Drafts

Showing results for 
Search instead for 
Did you mean: 

LabVIEW Lookup Table Program

by Member Sanjay_C. on ‎12-29-2010 01:20 PM

Introduction

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. The example program posted here illustrates how to perform a lookup from a table of data saved in a spreadsheet file. The example uses data composed of 3 different parameters, located in a  .CSV file. The user has the ability to perform a lookup with 1 or 2 parameters. The goal of this example is to illustrate the key components of a lookup system, such that more complex lookups can be derived from learning from this example.

Steps to Complete

  1. Download the attached files to one directory or Download the .ZIP (which contains all of the files) and extract to one directory.
  2. Open the LUT.vi, and specify the filepath 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
  4. 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.
  5. Stop the program and investigate the block diagram, which is heavily commented to describe the implementation logic.

Additional Notes

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.

Version Information

This example was written in LabVIEW 2010.

Comments
Member yin_the_novice
Member

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

Member Sanjay_C.
Member

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.

Member yin_the_novice
Member

thanks for the upload Sanjay !

Yin

Active Participant 1984
Active Participant

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.

Active Participant 1984
Active Participant

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

Member dfp
Member

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.