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

7 次查看(过去 30 天)
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 个评论
Denis Gurchenkov
Denis Gurchenkov 2015-8-25
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.

请先登录,再进行评论。

回答(1 个)

Rohit Jain
Rohit Jain 2015-8-26
To Enable Variable size data using command line, you may find below link useful:
Thanks Rohit
  1 个评论
Nils Lande
Nils Lande 2015-8-26
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by