Some of my variables are not initialized when converted to C using Coder

1 Ansicht (letzte 30 Tage)
I am trying to learn Matlab Coder using the tutorials and example files.
When I convert the following .m code into C++ code using Matlab Coder the block of code addressing x_est and p_est is ignored as seen in the generated C++ code that follows. I have looked through all of the other accompying files created by Coder and it is not addressed in any of them either. Is there a reason for this?
** Matlab .m code:
% Copyright 2010 The MathWorks, Inc.
function y = Temp(z)
%#codegen
persistent x_est p_est % Initial state conditions
if isempty(x_est)
x_est = zeros(6, 1); % x_est=[x,y,Vx,Vy,Ax,Ay]'
p_est = zeros(6, 6);
end
% Pre-allocate output signal:
y=zeros(size(z));
end % of the function
** Matlab Coder C++ generated code:
/*
* Temp.c
*
* Code generation for function 'Temp'
*
* C source code generated on: Tue Dec 04 15:45:49 2012
*
*/
/* Include files */
#include "rt_nonfinite.h"
#include "Temp.h"
/*
* function y = Temp(z)
*/
void Temp(const real_T z[10], real_T y[10])
{
memset(&y[0], 0, 10U * sizeof(real_T));
/* of the function */
}
/* End of code generation (Temp.c) */

Akzeptierte Antwort

Arnab De
Arnab De am 5 Dez. 2012
The variables x_est and p_est are not used in the MATLAB code. Therefore the compiler eliminates them.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by