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

1 次查看(过去 30 天)
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) */

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by