The “2-D lookup table” block in Simulink outputs the table value at the intersection of the row and column breakpoints. Here, since you want to estimate the current based on the torque and speed data, the current needs to be a 2D array corresponding to the specified torque and speed values.
Since the data for “Torque”, “Speed”, and “Current” is in 1D arrays, you need to create a grid of torque and speed values using the “meshgrid” function.
To estimate current at unmeasured torque and speed values, you will need to perform interpolation over the surface defined by these variables. Note that interpolation is valid only within the convex hull of your data points; outside this region, interpolation results in "NaN" values.
In case you want to cover the entire range of grid values, you can extrapolate the data to fill in the remaining values, which were not calculated during interpolation. However, extrapolation is often not very accurate and can lead to inaccurate estimates outside the data range.
Here is an example code to help you with this.
[torqueGrid, speedGrid] = meshgrid(linspace(min(Torque), max(Torque), 20), ...
linspace(min(Speed), max(Speed), 20));
F = scatteredInterpolant(Torque, Speed, Current, 'linear', 'nearest');
currentInterp = F(torqueGrid, speedGrid);
The “meshgrid” function creates a grid of torque and speed values over the range of provided samples. The “scatteredInterpolant” function creates an interpolant object that fits a surface over the provided vector values of torque and speed. The interpolation method is specified as “linear”, and the extrapolation method is specified as “nearest” here. You can customise this based on your requirements.
You can read more about the function by referring to the documentation, by using the following command in the MATLAB command window:
web(fullfile(docroot, 'matlab/ref/scatteredInterpolant.html'))
Once the interpolant object is created, the current values can be interpolated over the “Torque” and “Speed” grid to create a 2D array of current values.
You can now use this data in the Simulink “2D lookup table” block, by specifying the table data as “currentInterp”, and the 2 breakpoints as the unique values in “torqueGrid” and “speedGrid” respectively.