Filter löschen
Filter löschen

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

6 Ansichten (letzte 30 Tage)
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.

Antworten (1)

srj4anoop
srj4anoop am 11 Mai 2016
Bearbeitet: srj4anoop am 11 Mai 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 Kommentar
Alex
Alex am 13 Mai 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by