MATLAB Coder - Variable Size Matrix Input

3 ビュー (過去 30 日間)
Brian Millikan
Brian Millikan 2015 年 2 月 9 日
回答済み: Ryan Livingston 2015 年 2 月 9 日
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?

回答 (2 件)

Ryan Livingston
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.

Sean de Wolski
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.

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by