matlab coder:Can the C++ functions generated for the entry point functions of the "arguments" validation syntax take mergeability into account?
1 回表示 (過去 30 日間)
古いコメントを表示
cui,xingxing
2023 年 2 月 14 日
コメント済み: cui,xingxing
2023 年 2 月 14 日
For example, there is such an entry-point function in matlab that needs to generate C/C++ code, and I have generated several functions that are suitable for "different" types using the following command line, can these functions be merged into one for code simplicity and readability?
function out = useDefault(a,st)%#codegen
arguments
a (1,1) double
st (1,1) struct = struct("name","cuixing",...
"score",100);
end
% Specify the class of the input as struct.
assert(isstruct(st)); % https://www.mathworks.com/help/coder/ug/define-input-properties-programmatically-in-the-matlab-file.html#bq_w7jz-1
% Specify the class and size of the fields.
% assert(isa(st.name,'string')); %https://www.mathworks.com/help/coder/ug/define-string-scalar-inputs.html
assert(isa(st.score,'double'));
out = a + st.score;
end
command line:
codegen -config:lib -c -args {1,struct('name',"zhang",'score',50)} -args {100} -args {20,struct('name',"ab",'score',20)} -report useDefault -lang:c++
Note: I have specified the input multiple times with the "-args" parameter to represent a wider range of input types.

The resulting C++ code then has multiple similar functions for each `-args`, which does not take advantage of the overloading feature in C++ or use the default argument feature inherent in C++, could this be improved?
0 件のコメント
採用された回答
Bhargava Hurulagere Sridharamurthy
2023 年 2 月 14 日
Hi Cui,
Thanks for the inputs.
"Overloading feature" is unfortunately not supported in MATLAB Coder as of MATLAB 2022b. We've made an internal note of your request so we can look at lifting that limitation in the future.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!