How to define input types in Matlab Coder for a function that has a varying number of input?

2 visualizzazioni (ultimi 30 giorni)
I have a function let's say sq_dist(). This function can be called like this sq_dist(a,b) or sq_dist(a). This function includes slow operations and thus I am trying to make a Mex version of it hoping that it will run faster. I am using the Matlab Coder GUI to do so. In order to define input types (in the define input screen) i use a function that calls sq_dist(a,b) and sq_dist(a) to automatically determine input. This gives me an error: Error determining type for input sq_dist:b. Index exceeds matrix dimensions. Here is my function:
n = 50;
dim = 50;
a = rand(n, dim);
b = rand(n, dim);
u = sq_dist(a, b);
v = sq_dist(a);
So, since sq_dist can be called in different ways I am not sure how to define its input in the Coder.
If i manually set the input to double :inf x :inf for a and b the mex file is compiled but i get a runtime error: Function 'sq_dist' called with wrong number of arguments: expected 2, received 1.

Risposte (1)

srj4anoop
srj4anoop il 11 Mag 2016
Modificato: srj4anoop il 11 Mag 2016
Hi Alex,
You can make use of 'varargin' keyword to pass variable number of arguments to a function. For more info on varargin refer the following link
Also, refer to the following link on the rules to follow while using 'varargin' for code generation
  1 Commento
Alex
Alex il 13 Mag 2016
It is still not very clear how to use varargin given the code I have given above in the context of Matlab Coder, specifically after reading the limitations from the link you suggested.

Accedi per commentare.

Categorie

Scopri di più su MATLAB Coder in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by