Model Export to MATLAB®
When you export a model to MATLAB®, for each model/output, an M script is created that makes a model prediction.
This M script does not use ASCMO code and is therefore independent of an ASCMO installation. However, an installed MATLAB environment is a prerequisite for exporting to MATLAB.
Output Types
In the export dialog you can choose what to export.
For a model output named Y1 and the base name predict, the script predict_Y1.m is created.
The call is as follows: y = predict_Y1(x).
x is a vector of length equal to the number of inputs. The function returns a scalar, the model prediction.
With 4 inputs and output named Y1.
>> x = [0.3 7.5 100 66.1];
>> y = predict_Y1(x)
>> y =
>> 0.503
You can also enter a matrix in which the number of columns corresponds to the number of inputs. Each row corresponds to an input value to the model. The output is a vector whose ith component is the model prediction for the ith row (input value).
Additional outputs can be exported for the ASC GP model type.
For each model/output, a MATLAB® class is generated as an M file and an associated MAT file that makes a model prediction.
In addition to the model prediction, the following output values are exported:
- Gradient of the model prediction
- Hessian matrix of the model prediction
- Sigma (standard deviation) of the model prediction
- Gradient of the Sigma
- Model validity (Valid Model Range)
The gradient is needed, for example, if you want to use a gradient optimizer with the models.
When you export a model with the Model Prediction, Gradient, Hessian, Sigma, Sigma Gradient, and Validity type, the exported MAT files can be very large because a large matrix is required.
For a model output named Y1 and the base name predict, the script predict_Y1.ma file predict_Y1.mat are created.
Model Prediction and Gradient
>> M = predict_Y1;
>> [y, yGrad] = M.modelval_ygrad([0.3 7.5 100 66.1]);
Model Prediction, Gradient and Hessian
>> M = predict_Y1
>> Y = M.modelval(x)
>> [Y, Ygrad, Yhessian] = M.modelval_hessian(x);
Model Prediction, Gradient, Hessian, Sigma, Sigma Gradient, and Validity
>> M = predict_Y1;
>> Y = M.modelval(x)
>> [Y, Ystd_1, Ystd_2] = M.modelval_std(x)
>> [Y, Ygrad, Yhessian, Ystd_1, Ystd_2, Ystd_1grad, Ystd_2grad, Ystdgrad_t, Validity] = M.modelval_ygrad_std(x)
Note |
---|
If MATLAB® and Simulink® are not installed on your computer, you can export the model to a MATLAB® script (*.m) via File > Export Model > Simulink Script. This script can later be used to create a Simulink model. |
See also