Can I use coder.ceval to call other matlab coded function with dynamic coder::array<> in interface?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
Is it possible to split bigger MATLAB project into smaller modules, run CODER on those parts to produce static libraries, and later 'glue' it in MATLAB to produce executable binary?
I've tried with coder.ceval but the problem is with passing dynamic arrays.
Very simplified example:
- foo.m function is my 'module'
function y = foo(first, size)
y = zeros(size, 1, 'single');
y(:) = first + single((0:size-1));
end
- generated by CODER interface for this function would be
void foo(float b_first, int size, coder::array<float, 1U> &y);
- call foo() in main.m function
function ret = main()
if coder.target('MATLAB')
y = foo(10, 8);
else
coder.cinclude('foo.h');
% ????
end
ret = sum(y);
end
I successfully built executable binary for this example by using static size arrays, but in some cases, it won't be applicable or could be error-prone.
Thanks in advace.
0 Commenti
Risposte (1)
Infinite_king
il 25 Mar 2024
Hi Adam Przybyla,
It is possible to split the entire code into modules and then generate code for these modules using MATLAB Coder or any other Coder products. However, in all cases, it may not be possible to use a MATLAB script to combine all these libraries. I would recommend using C++ to combine all libraries and generate a single static library.
"Coder::array" is a C++ template that should be used to call functions that will return or take arrays of variable size as input or output in C++ code that was generated using MATLAB Coder.
For more information on how to use Dynamically Allocated C++ Arrays, refer to the following resource, https://www.mathworks.com/help/coder/ug/use-dynamically-allocated-cpps-arrays-in-generated-function-interfaces.html
Hope this is helpful.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!