Borrar filtros
Borrar filtros

Can I use coder.ceval to call other matlab coded function with dynamic coder::array<> in interface?

1 visualización (últimos 30 días)
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.

Respuestas (1)

Infinite_king
Infinite_king el 25 de Mzo. de 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.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by