What's the most memory efficient way to initialize a matrix to zero in Simulink?

I've noticed the autocoder stores the initial matrix from a constant block in global memory even if the matrix is all zeros or is initialized to zero on each iteration. I've used a gain block with a zero after the constant block to get different behavior in different parts of the autocode. I'd like memset() to be used so I can eliminate the reference to the global memory which is all zeros.
I'm using Matlab 2010b to generate the autocode from the Simulink model.
For example, I have a matrix of size 30x30 and I want to initialize the matrix to zero then set the elements of the matrix individually. I've noticed the autocoder stores the initial matrix as global variable even (if it is ALL zeros) then copies the zero matrix to the variable using a for loop. I thought I had found a solution by using a gain block of zero immediately after the constant block because in some instances I get the desired behavior of using memset():
/* Gain: '<S10>/Replace memcpy() with memset()' incorporates:
* Constant: '<S10>/Constant'
*/
memset((void *)
(&localB->B
[0]), 0, 900U * sizeof(real_T));
but in other instances the autocode uses a for loop and the global variable:
/* Gain: '<S17>/Replace memcpy() with memset()' incorporates:
* Constant: '<S17>/Constant'
*/
for (i = 0; i < 900; i++) {
Subsystem_1Hz_B.Q_g[i] = 0.0 * zero_ns_x_ns[i];
}
to set the matrix equal to zero.
I was hoping the autocoder would always use memset() so I could get rid of the zero_ns_x_ns variable from global memory. Note: zero_ns_x_ns is not used anywhere else in the code except to initialize a variable to zero.
Any recommendation on an efficient way to create a zero matrix and set the elements?

Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Asked:

on 4 Jun 2013

Community Treasure Hunt

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

Start Hunting!