How to troubleshhot Code generation error messages ('Dimension 2 is fixed on the left-hand side')?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Denis Gurchenkov
le 25 Août 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.
Réponses (1)
Rohit Jain
le 26 Août 2015
To Enable Variable size data using command line, you may find below link useful:
Thanks Rohit
Voir également
Catégories
En savoir plus sur Simulink Coder dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!