Main Content

Export Fit from Curve Fitter App to Simulink Lookup Table

This example shows how to create a surface fit using the Curve Fitter app, and then export the fit to a Simulink® 2-D Lookup Table (Simulink). You can follow the same workflow to export a curve fit to a 1-D Lookup Table (Simulink).

Create Surface Fit in Curve Fitter App

Load the BatteryDataFitter data set at the MATLAB® command line. The table batteryMeasurementData in the data set contains three battery measurement variables: Temperature, SOC (State of Charge), and Resistance.

load BatteryDataFitter

Open the Curve Fitter app.

curveFitter

Alternatively, on the Apps tab, in the Math, Statistics and Optimization group, click Curve Fitter.

In the Curve Fitter app, select the data variables for the fit. On the Curve Fitter tab, in the Data section, click Select Data. In the Select Fitting Data dialog box, first, select the table name batteryMeasurementData. Then, select Temperature as the X data value, SOC as the Y data value, and Resistance as the Z data value.

curvefitter_lut_selectdata.png

The Curve Fitter app plots the data points as you select variables. By default, the app creates an interpolant surface fit that passes through the data points. To obtain a smoother fit, in the Fit Options pane, select Thin-plate spline for Method. For more details, see About Interpolation Methods.

curvefitter_lut_fitoptions.png

The app creates an interpolant fit with thin-plate interpolation. Note that the data has two outliers. To remove the outliers, click Exclude outliers in the axes toolbar, and then click each outlier in the fit plot.

curvefitter_lut_outliers.png

The interpolant surface fit plot now excludes the two outliers.

curvefitter_lut_fit.png

Export Fit to Simulink Lookup Table

In the Curve Fitter app, in the Export section, click Export and select Create Simulink Lookup Table.

curvefitter_lut_export.png

Use the Create Simulink Lookup Table dialog box to specify the Breakpoints 1 and Breakpoints 2 values for the Temperature and SOC variables. You can specify the breakpoints as a set of explicit or even-spaced values.

The Explicit values option allows you to specify the breakpoints by using any expression that returns a vector. For example, you can use the colon operator (as shown in the following figure), a comma-separated list (for example, 240, 255.6, 271.2, 286.8, 302.4), or a function (for example, exp(1:10)).

curvefitter_lut_explicit.png

The Even spacing option allows you to specify a set of evenly spaced breakpoints. For each breakpoint set, specify the first point, spacing, and number of points.

curvefitter_lut_evenspacing.png

In this case, accept the default options and click Create Lookup Table.

Simulink Model with Lookup Table

The app opens a new Simulink model containing a 2-D lookup table block. The name of the block is surfaceblock (or curveblock if you create it from a curve fit). The model also has two constant inputs (or one input for a curve fit) and a display output.

curvefitter_lut_model.png

By default, the Extrapolation method is set to Clip. You can edit the Extrapolation method and other methods by double-clicking the lookup table block and displaying the Algorithm tab in the Block Parameters dialog box.

curvefitter_lut_block_algorithms.png

To view and edit the breakpoints, click Edit table and breakpoints on the Table and Breakpoints tab of the Block Parameters dialog box. For an example on how to edit the breakpoints, see Enter Breakpoints and Table Data (Simulink).

curvefitter_lut_block.png

Use Lookup Table in Another Simulink Model

You can use the lookup table created by the Curve Fitter app in another Simulink model. Copy the surfaceblock block and paste it into a new or existing model. You must also copy and paste surfaceBlockParameters from the model workspace of the current model to the other model's workspace. surfaceBlockParameters is a Simulink.LookupTable (Simulink) object. To find the surfaceBlockParameters object, on the Modeling tab, in the Design section, click the arrow to display the gallery and select Model Workspace under Repositories. In the model workspace, you can also configure the code generation settings.

curvefitter_lut_modelworkspace.png

See Also

Apps

Blocks

Objects

Related Topics