Populating a 3D lookup table

39 views (last 30 days)
Stephen
Stephen on 7 Aug 2011
I have a simple 3x512 array (x,y,z) in an ascii table file that is located in a directory.
I want to create Simulink lookup table that accepts values for y and z and returns the corresponding interpolated x value.
Is there a way that I can populate the lookup table with the contents of the array in the ascii file? Most examples I see involve manual entry of individual data triplets. I just want to load the file.
Thanks.

Answers (5)

Image Analyst
Image Analyst on 7 Aug 2011
A 3 x 512 array is a 2D array, not a 3D array. Assuming you've read your ASCII table into an array in your program (perhaps using csvread or dlmread), you could do something like (untested)
[rows columns] = size(array3x512);
for row = 1 : rows
x = array3x512(row, 1);
y = array3x512(row, 2);
z = array3x512(row, 3);
lut2D(y, z) = x;
end
Then later, when you have some arbitrary y and z that you want the x for, you just say
x = lut2d(y,z);
Of course you'll have to round all your indexes to integers - that's required if you want to do a look up table instead of interpolation. You may also have to figure out what to do if every single y and z pair is not represented.

Stephen
Stephen on 7 Aug 2011
Thanks.
I'm sure your suggestion would work with a Matlab script, but I'm trying to use a Simulink lookup table.

Stephen
Stephen on 8 Aug 2011
I decided just to create a function. I used SFTools to curve fit the data and SFTool was able to provide a function that fitted too.

Richard Willey
Richard Willey on 8 Aug 2011
Hi Stephen
I did a webinar a couple years back focusing on using sftool to generate lookup tables for Simulink.
The webinar includes (what I hope is) some useful code that you can use to optimize the location of the break points for the resulting LUT.
You can download the code from MATLAB Central

Stephen
Stephen on 8 Aug 2011
Thanks Richard, I will watch your webinar

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!