fitlookupn
Syntax
Description
fits an N-D lookup table to data specified by values
= fitlookupn(breakPoints
, inputData
, outputData
)breakPoints
,
inputData
, and outputData
and returns a lookup
table as an N-D array with a default smoothness penalty of one.
fits an N-D lookup table to data and returns a lookup table as an N-D array with the
smoothness penalty specified by values
= fitlookupn(breakPoints
, inputData
, outputData
, smoothnessPenalty
)smoothnessPenalty
.
specifies additional options using one or more name-value arguments. For example, you can
specify the bounds on the lookup table.values
= fitlookupn(___, Name=Value
)
Examples
Fit Data to N-D Lookup Table Using fitlookupn
Fit an N-D lookup table from scattered data using the fitlookupn
(Model-Based Calibration Toolbox) function.
Load Data and Create a 3-D Plot
Load the example data file dgasData.mat
. Use the plot3
function to create a 3-D plot.
load data.mat GasolineData plot3(GasolineData.LOAD,GasolineData.Speed,GasolineData.BSFC,'x') grid on xlabel('LOAD') ylabel('Speed [rpm]') zlabel('BSFC [g/Kwh]')
Define Breakpoints
Specify load and speed breakpoints in a cell array.
loadBreakpoints = 0.2:0.1:1.4; speedBreakpoints = 500:500:5000; breakPoints = { loadBreakpoints , speedBreakpoints };
Define Smoothness Penalty
Specify the smoothness penalty, smoothnessPenalty
, using the slider.
Note that the slider is on a log scale, as the smoothness penalty usually requires adjusting by several orders of magnitude.
smoothnessPenalty = 10.^
-2
smoothnessPenalty = 0.0100
Define Input Data
Set the load and speed as inputData
.
inputData = [GasolineData.LOAD,GasolineData.Speed];
Fit Lookup Table
Fit the lookup table using the fitlookupn
function and plot result.
[tableValues,rmse] = fitlookupn(breakPoints, inputData, ... GasolineData.BSFC, smoothnessPenalty, ShowPlot=true); grid on xlabel('LOAD') ylabel('Speed [rpm]') zlabel('BSFC [g/Kwh]')
Calculate Lookup Table Output
Use the griddedInterpolant
function to calculate the output from the lookup table. Calculate the lookup table value for LOAD=0.45
and Speed=2250rpm
and show on the plot.
Note:
You can use the interpn
function as an alternative to griddedInterpolant
.
rmse
rmse = 5.9891
%yinterpn = interpn(loadBreakpoints,speedBreakpoints,tableValues,x(1),x(2))
g = griddedInterpolant(breakPoints,tableValues);
x = [0.45, 2250];
y= g(x)
y = 269.5463
Specify Bounds
Specify bounds on the table values.
Note: An Optimization Toolbox™ license is required to fit lookup tables with bounds.
tableValues = fitlookupn(breakPoints, inputData, ... GasolineData.BSFC, 0.1, Bounds = [0 350], ... ShowPlot=true); grid on xlabel('LOAD') ylabel('Speed [rpm]') zlabel('BSFC [g/Kwh]')
Set Row-Major Order
You can use the IsRowMajor
option to change the order of the inputs (first input=columns, second input=rows). The resulting lookup table is the transpose of the default value IsRowMajor=false
.
tableValuesRM = fitlookupn(breakPoints, inputData, ... GasolineData.BSFC, 0.1, ... IsRowMajor=true, ... ShowPlot=true); grid on ylabel('LOAD') xlabel('Speed [rpm]') zlabel('BSFC [g/Kwh]')
Use the griddedInterpolant
function to calculate the output from the lookup table. Calculate the lookup table value for LOAD=0.45
and Speed=2250rpm
and show the results on the plot. You must swap the breakpoints and input order when IsRowMajor
=true
.
breakPointsRM = {speedBreakpoints, loadBreakpoints}; g = griddedInterpolant(breakPointsRM,tableValuesRM); xrm = [2250 0.45]; y= g(xrm)
y = 273.6243
hold on plot3(xrm(1),xrm(2),y,'.r','MarkerSize',20) hold off view([-20 37])
When you use the interp2
function, the inputs are already in row-major (meshgrid
) order.
yinterpn = interpn(speedBreakpoints,loadBreakpoints, ...
tableValuesRM,xrm(1),xrm(2))
yinterpn = 273.6243
yinterp2 = interp2(loadBreakpoints,speedBreakpoints, ...
tableValuesRM,x(1),x(2))
yinterp2 = 273.6243
Input Arguments
breakPoints
— Breakpoints
cell array
Breakpoints, specified as a cell array. Each element of
breakPoints
must be strictly increasing vectors of
doubles.
Note
The order of the first two dimensions is specified by the
IsRowMajor
name-value argument.
inputData
— Input data
matrix
Input data, specified as a matrix for the lookup table. The number of columns in
inputData
must equal the number of columns in
breakPoints
.
Note
Extrapolation is not supported.
outputData
— Output data
vector
Output data, specified as a vector. The number of rows in
outputData
must equal number of rows in
inputData
.
smoothnessPenalty
— Smoothness penalty
1 (default) | real positive scalar
Smoothness penalty for fitting the lookup table, specified as a real positive scalar.
The smoothness penalty is measured by second divided differences of lookup tables. The larger the smoothness penalty, the smoother the lookup table will be, but the match between the data and the lookup table will be worse. You might need to experiment with several values for smoothness to find an acceptable compromise between the goodness of fit and lookup table smoothness.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: values = fitlookupn(---,
Bounds=[-inf,inf],RegularizerType='laplacian')
Bounds
— Lower and upper bounds
1-by-2 array
Lower and upper bounds for the lookup table elements, specified as a 1-by-2 array, in the range [min,max].
Example: Bounds=[-100,100]
Note
An Optimization Toolbox™ license is required to specify bounds.
IsRowMajor
— Option to use row-major order
false
(default) | true
Option to use row-major order, specified as true
or
false
.
When IsRowMajor=true
, the first dimension is a columns and the
second dimension is a row.
Setting IsRowMajor=true
is useful for graphics applications
where the first dimension is X
and the second dimension is
Y
.
Example: IsRowMajor=true
ShowPlot
— Option to show fitted 1-D or 2-D lookup tables and data
false
(default) |
true
Option to show fitted 1-D or 2-D lookup tables and data, specified as
true
or false
.
Example: ShowPlot=true
Output Arguments
values
— N-D lookup table
N-D double array
N-D lookup table, specified as an N-D double array, where the number of dimensions is the number of breakpoints.
Version History
Introduced in R2023b
See Also
Fill Feature Lookup Tables (Model-Based Calibration Toolbox)
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)