How to troubleshhot Code generation error messages ('Dimension 2 is fixed on the left-hand side')?

4 visualizzazioni (ultimi 30 giorni)
I have been struggeling with a tricky error message that I get during code generation.
I have a Simulink model that contains a block of type 'MATLAB Function' with MATLAB code inside it.
When I generate code for this model I get this error message:
??? Dimension 2 is fixed on the left-hand side but varies on the right ([1 x 1] ~= [1 x :?]).
I have read the documentation and googled it and understand what can cause this error. The problem is that the coder does not point at the location in the code where the problem is. The error is raised much later in the code in the caller of the function where the problem is.
Finding the lines of code that caused the problem took at lot of time since it was in another file than the one pointed to by the error message.
I found that if I generated the code using MATLAB Coder (keeping Simulink out of the loop) with a configuration where variable sizing was disabled (cfg.EnableVariableSizing = 0;) I would get an error message pointing to the correct location. The error message was:
??? Operands must be constants.
The code causing the problem looked something like this:
if myStruct.myVar < 0,
x = 1:par.myVarMax;
else
x = mytruct.myVar;
end
None of my test scenarios actually had a value for 'myStruct.myVar' that was below 0 so the dimentions were always identical on both sides of the calculation that happened at the line were the original error message pointed to.
So my questions are:
- Are there any tricks I could use when troubleshooting Coder errors? Is there any logging going on, any settings I can change to make it more detailed, etc.
- Is it possible to set the 'EnableVariableSizing' option from Simulink?
I am using MATLAB R2014b.
  2 Commenti
Denis Gurchenkov
Denis Gurchenkov il 25 Ago 2015
You can change the EnableVariableSizing options in the block properties. When you are editing the source code of your MATLAB Function Block, click the "Edit Data" button on the tool strip, and then uncheck "Support variable-sized arrays". That will have same effect as EnableVariableSizing = 0 in codegen.

Accedi per commentare.

Risposte (1)

Rohit Jain
Rohit Jain il 26 Ago 2015
To Enable Variable size data using command line, you may find below link useful:
Thanks Rohit
  1 Commento
Nils Lande
Nils Lande il 26 Ago 2015
Thank you for the suggestion Rohit,
I have managed to set the option when using the coder in MATLAB as you describe. The problem was to do the same when creating the code from a Simulink diagram using the command:
rtwbuild(modelName);
I think Denis' suggestion is what I was looking for.

Accedi per commentare.

Categorie

Scopri di più su Simulink Coder in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by