Containers.Map and struct with dynamic field names not supported in code generation
Show older comments
Hello there,
Now I have finished a hybrid A* Planner in Matlab and would like C++ code generation. (though there is plannerhybridastar embedded in Matlab.) In this planner is containers.Map used for open set. But the coder said it does not support.
It’s not cool but I am not so surprised. I try the workaround with struct array. The field name is the ID of nodes and the value is node (instantiated object). With “isfield” it can check, whether a ID in struct exist. It works in Matlab

but again the code generation fails with error:
Non-constant expression or empty matrix. This expression must be constant because its value determines the size or class of some expression.
at following:
obj.structName.(fieldName)= node;
% assign “node” to field name in structName
In which fieldName is a variable with type char and will be updated. After a small study the reason should be, Coder does not support accessing the fields of a structure using dynamic field names.
But in my opinion, it is necessary that “fieldName” as dynamic, because it is unknown and will be assigned.
Now I am confused and do not know if there is workaround or solution. Actually, what I need is something which is supported by code generation and can store key and value accordingly. As above, the value is instantiated object.
Do you have some ideas and could you help me? Thanks in advance.
Best Regards
Yan
Accepted Answer
More Answers (0)
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!