Matlab code generator generates a error stating "Undefined function or variable. The first assignment to a local variable determines its class."
8 views (last 30 days)
Show older comments
Hello,
When i am trying to generate a C code from Matlab code generat the following error occurs.
" Undefined function or variable 'ext'. The first assignment to a local variable determines its class"
My Code is given below :
function extremePoints()
state = [0 10 20 50 30 20 60 70 60 10]
dSOC = diff(state);
sgn = sign(dSOC);
ext(1)=0;
j=2;
%finding extremes of state
for i=2:length(state)-1
if sgn(i-1) ~= sgn(i)
ext(j)=state(i);
j=j+1;
end
end
ext(j)=state(end)
end
I have used coder.varsize, but it dosent work or i have not used efficiently. Please solve the problem.
4 Comments
infinity
on 11 Aug 2019
To handle the problem of unknown lenght of ext, you can first assume ext as a vector of a large length of NaN, for example, ext = NaN(1,1000). ext finally contains your desire values and some NaN that can be treated as non-number.
Walter Roberson
on 11 Aug 2019
It is possible to create resizeable matrices, but it involves memory allocation routines which can lead to challenges for real time work. It is typically better to use a different approach:
decide on a maximum size that will not be exceeded unless the program gets rebuilt. Use the size() (not length()) of an input as the size for zeros() to initialize the array. But also add an assert() just before that that checks that the size is no more than the limit you are willing to impose.
Coder knows how to use the assert() to allocate maximum stack sizes if needed, for efficient allocation and ability to confirm that the maximum stack will not exceed the available memory of the processor.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!