LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a 3D lookup table from CSV

Solved!
Go to solution

Hi,

 

Im Quite new in Labview and Im trying to create a 3D lookup table from a CSV File.

 

I have a CSV file consisting of three inputs (X, Y and Z) and one output, W. My idea is that I read the CSV file with the read delimited spreadsheet VI and then split the CSV file into 4 different arrays, three for the inputs and one for the output, after that I want to read in the inputs and output to the 3D lookup table block.

 

For the inputs (X,Y,Z) It is pretty straight forward to just connect them to the block, however my trouble starts for the output array (W).  The 3D LU table only accepts the LU Data (W) to be wired in as a 3D array. And Im not really sure of how to create a 3D array consisting of the outputs only.

 

I am now wondering if anyone has run into the same issue before and how that problem was solved? Or if anyone has an alternative approach to solve my problem.

 

I have attached both my VI and the CSV file into this post in the last row I have written how many unique values I have for each input. I have looked into other examples at both NI.com and in Labview and read documentation without any luck.

 

Best regards

0 Kudos
Message 1 of 40
(4,066 Views)

If your output, W, is a function of 3 variables X, Y, and Z, then you need some sort of 3D structure to allow you to do this.  A CSV file is basically a way to express a 2D structure, a function of X and Y, with no Z.  The idea is that for every (reasonable, or "usable") value of X and Y, you can assign a value of a dependent variable (W).

 

Suppose you wanted to describe an Image by telling me the "brightness" of a pixel, with 0 being Black and 255 being white.  You could write a CSV that had 480 rows of 640 columns of bytes, and I could interpret these as pixels and make a 2D Image.  Suppose I wanted to see this Image "evolve" by adding a third dimension, namely "time" (I'll call this a "Video").  I can't do this with a CSV file -- I need one CSV file for every "frame" of my Image.

 

Of course, it is possible to write N-dimensional Arrays to disk, but the structure is a little more complicated than the simple 2D structure of the CSV format, designed for only 2D data.

 

Bob Schor

0 Kudos
Message 2 of 40
(4,042 Views)

Hi Bob,

 

I appreciate your answer.

 

Maybe I should have been more clear in my first message. 

 

The output values have already been calculated in  a Matlab script, where X, Y, and Z were the inputs for the calculations in the script, after that, I saved them to a CSV file since I found that format suitable to use since it can easily be read by the LabVIEW VI. 

 

However, now I just want to assemble the outputs in a proper 3D Lu table and as I have understood it the outputs (w) need to be in 3D array format which makes sense but I'm not really sure how to implement that in LabVIEW. I also want to have X as rows, Y as columns and Z as pages (or planes if you like) So that a certain combination of X, Y, and Z corresponds to the calculated w value from my script. Maybe this is not even possible to implement in Labview?

0 Kudos
Message 3 of 40
(4,027 Views)

It almost sounds like you are dealing with Quaternions?

0 Kudos
Message 4 of 40
(4,005 Views)

@antje668 wrote:

I also want to have X as rows, Y as columns and Z as pages (or planes if you like) So that a certain combination of X, Y, and Z corresponds to the calculated w value from my script.


Is there a reason why you want it to be that way?

 

If you are content to look up only specific values, you may get away with a map of (x,y,z) -> w. Read the CSV and add each line to the map.

 

Arrays may be a bit tricky if your data is sparse. Also, it seems that the last line of your csv is the dimensionality. You might want to move that to the top, where it is needed - or remove that altogether. You might also consider explicitly saving the grid points somewhere.

 

Then you

  • read the CSV
  • separate out the axes
  • get the grid points (either explicitly from another file or by removing duplicates from the axes)
  • initialize the 3d-grid
  • for each line, get the target index by looking up the coordinates on the grid
  • set the value in the array at the target index

 

The last three steps could look like this, getting the grid can be solved by exporting the data in the first place.

LLindenbauer_0-1654848995728.png

 

0 Kudos
Message 5 of 40
(3,996 Views)

Thank you for your answer, it was very specific and well detailed. The reason for why I want x,y,z in the order Is that because specific combination of x,y,z gives a specific output w. Why I want x as row, y as column, and z as pages (planes if you like) is because it makes most sense for me. But I think i might as well could have for example y, as row, z, as column and x as plane aswell. The combination is just something I have chosen. 


Why a lookup table is best suited for this task is because I also want to interpolate between the values, let's say I give a combination of x,y,z that I don't have values for, but they might still be in the middle of a range between the values that I have, if so I want the output to be an interpolated value.

 

Why I have so many different duplicates of for example x is because the different combinations of x,y,z in the CSV file give a unique value.

 

What i did not fully understand is how i could get the grid points from another file? The duplicates are still gonna be needed for this task I think.

0 Kudos
Message 6 of 40
(3,989 Views)

I also realized maybe a matrix consisting of the outputs is more suited for the task then an array?

0 Kudos
Message 7 of 40
(3,934 Views)

@antje668 wrote:

 

 

What i did not fully understand is how i could get the grid points from another file? The duplicates are still gonna be needed for this task I think.


Yes. I think it will become clear when it is expressed as a mapping.

 

Your 3-dimensional array is accessed using integer indices, so that

(Ix, Iy, Iz) -> W

 

Where Ix is the index into the data structure for X-value x.

So you need a mapping of

x <-> Ix

 

This mapping is what I refer to as "Grid". The grid is a list for the X, Y and Z-Values for which you will give me the W-values in the file, so that I know to access the array at (0,0,0) when you want the W-value for (73000, 0.13, -5.1). I can also use the grid to find the indices I need for interpolation, so that I can find that for

 

x = 73001 means that 0 <= Ix, frac <= 1

 

 

You did not explicitly give the grid, but I can generate it myself by first looking through your file, taking note of every x, every y and every z present, then selecting only the unique values. This means I have to read the file twice. If you had given me the grid in advance, I only need to read the file once.

0 Kudos
Message 8 of 40
(3,980 Views)

Ok now I understand what you mean. However when I tried using that approach only the first element in the 3D array seemed to be filled in. While the other one stays as NaN. I have also created separated CSV files for the gridlines which I have also read in and connected to the search 1D array blocks. 

 

Can you see any clear mistake that I make? 

 

Also Im wondering to implement a Interpolation approach for the output values aswell, or maybe I can connect the block named "array" to the 3D lookup table block in the control & simulation and let that VI fix that for me? 

 

I have attached the new VI adapted to your proposal and the CSV files for each gridline.

 

 

0 Kudos
Message 9 of 40
(3,967 Views)

I'm sorry, I can't open your VI - maybe you can save for a previous version, Version 16 or lower? You could also post a snippet of the code. It's usually better to post complete VIs, but since you already did and the code is probably flat, I guess its OK.

0 Kudos
Message 10 of 40
(3,960 Views)