MATLAB Coder - Variable Size Matrix Input
3 次查看(过去 30 天)
显示 更早的评论
I am trying to use MATLAB code to generate a MEX file for some code which has an input matrix where one dimension is unknown in size. It also has a vector which is also unknown in size. How do I handle this in MATLAB coder? I know I can specify up to a maximum size by using :800x1 for a vector and :800x800 for a matrix. But, how does the code know what size to use?
0 个评论
回答(2 个)
Ryan Livingston
2015-2-9
The generated code will take the size as an argument. Suppose we have the function:
function y = varsize(x)
y = 2*x;
and generate code:
codegen varsize -args {coder.typeof(1,[80,80],[true,false])} -config:lib
The signature of the entry-point function in the generated code is:
void varsize(const double x_data[], const int x_size[2], double y_data[], int
y_size[2]);
so that the caller passes in x_size to specify the size of x. The generated code sets y_size to the size of the output so that the calling C code knows how large y is.
In some instances, the generated code will use structs to represent arrays. When this is the case, the size vectors will be embedded inside of the structure arguments:
void varsize(const emxArray_real_T *x, emxArray_real_T *y);
where emxArray_real_T is a struct that contains double data, a size vector, and other data.
0 个评论
Sean de Wolski
2015-2-9
The code provides the ability to work with any size in that range so that it does not need to know the size of the inputs (as long as they're in that range) beforehand.
Is that what you're asking? I'm not completely clear on the question.
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!