フィルターのクリア

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

6 ビュー (過去 30 日間)
Alex
Alex 2016 年 5 月 2 日
コメント済み: Alex 2016 年 5 月 13 日
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.

回答 (1 件)

srj4anoop
srj4anoop 2016 年 5 月 11 日
編集済み: srj4anoop 2016 年 5 月 11 日
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 件のコメント
Alex
Alex 2016 年 5 月 13 日
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.

サインインしてコメントする。

カテゴリ

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