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!