I have a 4-dimensional set of experimental data:
v = f(x,y,z)
Where:
- x, y, z, v are 1x20 vectors.
- f is UNKNOWN in fact it is what I need to estimate.
I want to calculate:
v_i = f(x_i, y_i, z_i)
For a different set of data (x_i. y_i, z_i) in Simulink.
The block LOOPUP N-D seems to be what I need, but I only get NaN on its output.
I have done this kind of interpolation already in M-code, using GRIDDATAN, and that worked fine.
May it be that I am using the lookup block wrong? I set parameters like this:
Breakpoint 1: x
Breakpoint 2: y
Breakpoint 3: z
Table: griddatan result on x,y,z evaluated on an uniform grid
I am not sure the Table is properly input, as I keep on getting NaN when I should not
Any idea, suggestion, shortcut ?
Thanks
I tried creating the following out of my data:
* 3 breakpoints, being of dimension 1x10:
x
y
z
* A table, a 3D diagonal matrix (10x10x10) with all the corresponding values of v on the diagonal of the matrix, and the rest ZERO.
But then I get the following error when I run simulink:
--> Values of BreakpointsForDimension1 in 'canistergasmodel02/Lookup Table (n-D)' must be monotonically
increasing. The problem occurs at the number 578667976 breakpoint. Please change the breakpoint data or use the
fixedpoint tools such as Auto Scaling or fixpoint advisor to determine a different parameter dialog type.
Then I used the 'sortrow' command to sort the 4D set data, but I still get this. For the record, my sorted 4D set of data is:
[x y z v]=
2.0000 23.6667 -91.0000 100.0000
2.0000 28.1667 -92.0000 105.0000
2.0000 27.2000 -88.0000 100.0000
5.0000 27.9000 20.0000 5.0000
5.0000 22.0333 20.0000 5.0000
5.0000 29.5333 20.0000 8.0000
20.0000 27.3000 20.0000 11.0000
20.0000 21.0000 20.0000 5.0000
25.0000 26.3667 20.0000 8.0000
40.0000 29.0000 20.0000 8.0000
First column is sorted, but it is impossible to have x y and z columns sorted simultaneously
So I do not see how to solve the problem, again
Ideas how I may use this lookup n-D block for my purpose?
- As breakpoints, one must use linearly spaced arrays
- As table, one must use a 3x3 matrix.
- Griddata can not interpolate data out of the convex volume formed by the scattered experimental points.
So this is what I did to get it right:
My experimental data is like this:
x, y, z, v , arrays of 1xn dimension
Which are related to one another in this form: v = f (x,y,z). The function 'f' is UNKNOWN.
I need to evaluate 'v' for different values on the 3D space {x,y,z}.
So I use first create a linearly spaced grid with 'meshgrid' using 3 vectors, defined in my target volume of interest:
x_linspace (1xn)
y_linspace(1xn)
z_linspace (1xn)
Then I use 'griddata3' to evaluate 'v' in this newly created grid, thus getting a 'v_griddata3' matrix which is nxnxn
So now we ALMOST have all the data ready for 'lookupnd' in simulink:
Breakpoints:
x_linspace (1xn)
y_linspace(1xn)
z_linspace (1xn)
Table:
v_griddata3 (nxnxn)
I mean ALMOST, because 'v_griddata3' maybe full of NaN as griddata can not interpolate data out of the convex volume formed by the scattered experimental points. A Table with a lot of NaNs will generate a lot of NaN, which is not desireable.
Therefore, we can use the wonderful 'inpaint_nan3' (check matlab central). This will extrapolate the current values in 'v_griddata3' in order to eliminate all NaN.
That is all. Interpolation must work fine then.
Thanks everybody who helped !
Álvaro