Extending variable in MATLAB Coder causes function body to disappear
显示 更早的评论
I have a MATLAB function which changes the size of a variable after it is defined. The variable is marked as variable size with the "coder.varsize" function, and MATLAB Coder allows the size of the variable to change:
function v = test_fcn()
coder.varsize("v", [1 2]);
v = 0;
v(end + 1) = 1;
rand;
end
When I compile this function using MATLAB Coder with the command
>> codegen -config cfg -o generated_code test_fcn
no warnings are emitted but the body of the resulting C function is empty:
void test_fcn(const double v_data[], const int v_size[2])
{
(void)v_data;
(void)v_size;
/* A check that is always false is detected at compile-time. Eliminating code
* that follows. */
}
The behavior of the function is now incorrect in two ways: (1) the return value is incorrect and (2) the code no longer calls "rand" and so no longer changes the state of the random number generator.
How do I make this code compile correctly?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!