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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by