2d Lookup tables to model starter Data
1 view (last 30 days)
Show older comments
I am using a few arrays that are 1D specifically arrays that invlude Torque, Speed and Current. I want to put the data into a 2d lookup table so that when you enter the Torque and Speed you can estimate the current needed to produce those speeds but I can not get that to work.
The Data is Torque [42;38;24;20;17;6;4] Speed [ 3500;4000;7125;7600;7650;8100;9000] and Current [1000;900;850;800;750;400;350]
I suppose I want to know if its possible to use this data in a 2d lookup table and if so how I would do it?
0 Comments
Answers (1)
Aabha
on 10 Feb 2025
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.
0 Comments
See Also
Categories
Find more on Nonlinearity 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!