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

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

Hi Piero,
Did you get to the bottom of this? also trying to figure out something similar.
Regards, Miriam

댓글을 달려면 로그인하십시오.

질문:

2014년 6월 18일

댓글:

2016년 3월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by