1

I am trying to implement a kind of lookup table in MATLAB.

I have data generated from a script with three variables swept, let's say var_a, var_b, var_c. These are nested sweep, (var_a -> var_b -> var_c) And there are 10 outputs, out_01, out02, ..., out10.

Now I have arranged the each output as out_01 = f(var_a,var_b,var_c), i.e., simply rearranging the data similar to nested loop.

My question is, how can I build a lookup table for such data? I will give input like get out_01 @ certain var_a(X), var_b(Y), var_c(Z).

I have tried the following.

    idx1_var_a   = max(find(data.var_a <= options.var_a));
    idx2_var_a   = min(find(data.var_a >= options.var_a));

    idx1_var_b = max(find(data.var_b <= options.var_b));
    idx2_var_b = min(find(data.var_b >= options.var_b));

    idx1_var_c = max(find(data.var_c <= options.var_c));
    idx2_var_c = min(find(data.var_c >= options.var_c));

    Y1 = interpn(data.var_c,data.var_b,data.var_a,data.out_01,data.var_c(idx1_var_c),data.var_b(idx1_var_b),data.var_a(idx1_var_a))

    Y2 = interpn(data.var_c,data.var_b,data.var_a,data.out_01,data.var_c(idx2_var_c),data.var_b(idx2_var_b),data.var_a(idx2_var_a))        

    if Y1 == Y2
        Y = Y1
    else        
        Here I am unable to figure how to interpolate between these two output values,Y1, and Y2!!
    end

Any help is welcome.

raggot
  • 992
  • 15
  • 38
avlsi
  • 11
  • 1
  • 3
  • Take a look at `interp1` - I think it is exactly what you need. Try it and update your answer if it doesn't work for you. – Floris Nov 08 '13 at 03:03
  • One way would be to use [Map](http://www.mathworks.com.au/help/matlab/map-containers.html). – Marcin Nov 08 '13 at 03:45
  • Thanks Floris, I was also thinking interp1 might work. It may be simple, can you point me to any example on how to use it? I have used interp1 for 1D data like this. interp1(var_a, out_01, X). To explain further, I want out_01 value to be output w.r.t var_a vector at a value of X, X can be part of var_a or else needs to interpolate. – avlsi Nov 08 '13 at 05:38

1 Answers1

1

I think you are looking for this:

Suppose you have:

var_a = 1:3;
var_b = 0:0.3:0.9;
var_c = 1:2;

[A, B, C] = ndgrid(var_a, var_b, var_c)

F = A.^3+B.^2+C;

Now you can directly acces the function at all existing points:

F(1,2,2) 

Or alternatively

F(var_a==1,var_b==0.3,var_c==2)

Now if you are interested in values between the gridpoints, you can use interp3

Vq = interp3(F,1.5,2.5,1.5)

Note that this takes the desired location in the vector as input.

Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
  • Hi Dennis, Thanks for the input. I am not getting the out_01, out_02 etc from MATLAB but from a different software. But I am rearranging them in matlab. – avlsi Nov 09 '13 at 13:48