question: Use of integrated external C/C++ code in matlab coder does not work for coder.varsize?
Show older comments
When I follow this topic "Call Custom C/C++ Code from the Generated Code" to generate my own external/legacy C++ code, coder.varsize('myvar') does not work. How do I declare 'myvar' to be a variable-length character vector or a variable-length scalar string?
function out = useImageAndString(imagePathList,image1)%#codegen
% generated C++ code, mainly to see the values passed for the input and output parameters
%
% reference:
% [1] coder.ceval
% [2] coder.opaque
arguments
imagePathList (1,1) string = "input.txt"
image1 (100,200) uint8 = zeros(100,200,'uint8')
end
if ~coder.target("MATLAB")
out = zeros(size(image1),"uint8");
% include external C++ functions
coder.cinclude('test1.h');
coder.updateBuildInfo('addSourceFiles', 'test1.cpp');
imgPath = char(imagePathList);% must convert to char???, can't pass string scalar to coder.rref, this is bug!
imgPath = 'input.txt'; % or i directly specify imgPath, also not work.
coder.varsize('imgPath'); % bug
coder.ceval('getImageNames',coder.rref(imgPath));
% call C++ function
coder.ceval('getImage', coder.rref(image1),coder.wref(out));
end
end
my test1.h like this:
void getImageNames(const char* imgList);
void getImage(const unsigned char inImage[20000],unsigned char outImage[20000]);
The input parameter `imgList` to the getImageNames function is a variable-length character vector or a variable-length scalar string. I tried coder.varsize to declare it, but the generated C++ code still fixes the length size with my example, how can I fix it?
codegen -config:mex useImageAndString -args {"111.txt",ones(100,200,"uint8")} -launchreport -lang:c++
For example, the example command above generates C++ code that fixes imagePathList argument the length to 7
run in R2022b
1 Comment
xingxingcui
on 17 Feb 2023
Edited: xingxingcui
on 17 Feb 2023
Accepted Answer
More Answers (0)
Categories
Find more on Algorithm Design Basics 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!