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

3 ビュー (過去 30 日間)
Nils Lande
Nils Lande 2015 年 8 月 21 日
コメント済み: Nils Lande 2015 年 8 月 26 日
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.
Nils Lande
Nils Lande 2015 年 8 月 26 日
Thanks a lot Denis, I think that is what I was looking for.

サインインしてコメントする。

回答 (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 Center および File ExchangeSimulink Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by