How to avoid a FOR loop in Simulink Code Generation when dealing with matrices ? Is it possible to use pointers ?

3 ビュー (過去 30 日間)
Hi everyone,
I'm working with code generation for simulink and I have the following problem:
- I have a switch block that is driven by an input signal and it selects and connect one of the two matrices [16 x 8] to an interpolation table (output):
Problem is that with this solution (switch block), the generated code creates a for cycle that copies the matrices in memory at each time sample (0.001s)...
/* Switch: '<S679>/Switch4' incorporates:
* Constant: '<Root>/input'
*: '<S679>/
* Constant: '<S679>/matrix_1'
* Constant: '<S679>/matrix_2'
*/
for (AS_ERT_B.U_lum5n = 0; AS_ERT_B.U_lum5n < 128; AS_ERT_B.U_lum5n++) {
if ( INPUT != 0) {
AS_ERT_B.Switch4_fhchw[AS_ERT_B.U_lum5n] =
matrix_1[AS_ERT_B.U_lum5n];
} else {
AS_ERT_B.Switch4_fhchw[AS_ERT_B.U_lum5n] =
matrix_2[AS_ERT_B.U_lum5n];
}
}
/* End of Switch: '<S679>/Switch4' */
...and it is very costly for the processor. One of the solutions is to use an "if action" system instead of the switch (it would eliminate the FOR iterations but uses memcopy), or even better, create a logic that connects directly each matrix to the interpolation table.
My question is: I know that with simulink we cannot "handle" pointers, but, is there a manner to do something like this (figure) ?
I mean, is there something that would output the ADDRESS of the selected matrix (for example a pointer) instead of generating a for cycle that copies the whole matrix or using memcopy ??
Thanks gentleman.
  1 件のコメント
Miriam Lorenzo
Miriam Lorenzo 2016 年 3 月 9 日
Hi Piero,
Did you get to the bottom of this? also trying to figure out something similar.
Regards, Miriam

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

回答 (1 件)

Piero
Piero 2014 年 6 月 26 日
Anyone ??

カテゴリ

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