MATLAB Coder - Variable Size Matrix Input
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Ryan Livingston
le 9 Fév 2015
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 commentaires
Sean de Wolski
le 9 Fév 2015
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 commentaires
Voir également
Catégories
En savoir plus sur MATLAB Coder dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!