Non-constant expression or empty matrix. This expression must be constant because its value determines the size or class of some expression.
显示 更早的评论
How should I correctly pass in variable structure fields to support C/C++ code generation? My problem is simplified by the fact that the field name "str" of the following structure is dynamically changing and the exact value can only be determined at runtime
function out = testStruct()%#codegen
s = struct();
for i = 1:3
str = randGenChar();
s.(str) = i;
end
out = s;
end
function str = randGenChar()
basechar = 'abcdefghijklmnopqrstuvwxyz';
idx = randi(numel(basechar));
str = basechar(1:idx);
end
Then execute command line:
codegen -config:mex testStruct.m -report
Non-constant expression or empty matrix. This expression must be constant
because its value determines the size or class of some expression.
Error in ==> testStruct Line: 6 Column: 8
Code generation failed: To view the report, open('codegen/mex/testStruct/html/report.mldatx')
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!