Hi I am using a C function in my MATLAB project and one of the inputs is a dynamic array, how can I modify this input since in build.m the inputs are set up and fixed. I want to be able to throw any array size in to it. Following you can find the files I am using:
bimi.c
#include "bimi.h"extern void bimi(int* poly, int* polysz, int* output){ int i; int a=*(polysz); for(i=0;i<a;i++){ output[i]=2*poly[i]; }}
bimi.h
extern void bimi(int* poly, int* polysz, int* output);
bimifunc.m
function y = bimifunc(poly2, polysz2) %#codegen
y = coder.nullcopy(zeros(1,5,'int32')); coder.updateBuildInfo('addSourceFiles','bimi.c'); fprintf('Running Custom C Code...\n\n'); coder.ceval('bimi',coder.ref(poly2),coder.ref(polysz2), coder.ref(y));end
build.m, this where the input size is setup and fixed, how can I make it dynamic?
function build(target) % Entry point function:
entryPoint = 'bimifunc';%
%Example input
poly=zeros(1,5, 'int32');%THIS WHERE I WANT THE DYNAMIC ARRAY OR IS THERE ANOTHER WAY?
polysz=int32(length(poly));* % Configuration object:
cfg = coder.config(target); % Custom source files:
cfg.CustomSource = 'bimi.c'; cfg.CustomSourceCode = [ '#include "bimi.h"' ]; % Generate and Launch Report:
cfg.GenerateReport = true; cfg.LaunchReport = false; % Generate Code:
codegen(entryPoint,'-args', {poly, polysz},'-config', cfg)end
test.m, I want to be able to generate any random size of array and throw it to the function for calculations.
%testing the c code embeded to matlab
poly=ones(1,5, 'int32'); polysz=int32(length(poly)); chichi=bimifunc_mex(poly, polysz);
Best Answer