Clear Filters
Clear Filters

Error generating code to implement RegressionGP Model using MATLAB Function in Simulink (The input to coder.const cannot be reduced to a constant: Unsupported value.)

3 views (last 30 days)
A strange problem occurs to me trying to integrate my trained RegressionGP in a Simulink Model using a MATLAB Function block, saveLearnerForCoder and loadLearnerForCoder.
I trained two GPs with the same size of predictors which is 75. I use the same script for training and optimization. The only difference are the measurements used for training. I use sequences of 25 datapoints from three sensors each.
The first GP works flawlessly in a matlab skript ans also in Simulink using a MATLAB Function block. The second GP works without problem in a MATLAB script. When I try to complie the same Simulink model with the second GP (change name of file in loadLearnerForCoder) I get the following error:
The input to coder.const cannot be reduced to a constant: Unsupported value. Function 'loadLearnerForCoder.m' (#76.1874.1895), line 41, column 68: "matFile.compactStruct" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'MATLAB Function2' (#55.201.239), line 10, column 7: "loadLearnerForCoder('gprMdl_V106_LUT')" Launch diagnostic report.
This is the function I use in both cases:
function [prediction, upperConf, lowerConf] = gpr_predict_V101(X) %#codegen
% Copyright 2019 The MathWorks, Inc.
prediction = 0.0;
confidence = [ 0.0 0.0 ];
upperConf = 0.0;
lowerConf = 0.0;
mdl = loadLearnerForCoder('gprMdl_V101_LUT');
[prediction, ~, confidence] = predict(mdl,X);
upperConf = confidence(:,1);
lowerConf = confidence(:,2);
The input data is preprocess the same way for both GPs and therefore has the same size. I checked all dimensions and compared the compacStruct created for both GP through saveLearnerForCoder and couldn't finde any difference besides the GP hyperparameters and ActiveSet used.
Does anyone know where else this error could come from?
Thanks in advance!

Accepted Answer

Denis Gurchenkov
Denis Gurchenkov on 4 Aug 2020
Hi Michelle, there is nothing wrong with your code, the issue looks like a bug in the product. Can you please contact MathWorks technical support, just tell the support person to route the ticket to MATLAB Coder team (this is where I work). If you are able to provide your (failing) model to the technical support, we should be able to reproduce the issue in-house and figure out what is going on and hopefully provide you with some workaround.

More Answers (1)

Sriram Padavettan
Sriram Padavettan on 4 Dec 2020
Not sure if you figured it out yet, but are you using 2020A?
I had same issue and messed with it all day until I decided to try a different version and it worked - try 2020B.
  1 Comment
Michelle Geilenberg
Michelle Geilenberg on 6 Dec 2020
Hi Sriram,
that is actually also the solution the Mathworks Support Team came up with. I had to wait a month for the 2020b release and was able to run my simulation without problems! Apparently there is a bug in the MATLAB Coder which gets resolved in R2020b.
Thanks for your help anyways! :)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!