1

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 Answer 1

1

In short, you cannot do what you want to do (with current version 2016a) for the top-level function - this has to have a defined number of inputs and outputs. Even if you use the 'varargin' parameter in the function definition, MATLAB Coder will generate the function with a fixed number of inputs based on the example arguments you provide.

If you have a particular function that has a variable number of input arguments, you can put a wrapper function (with a fixed number of input arguments) around the outside, and make the wrapper the top-level function.

Rules here: http://uk.mathworks.com/help/simulink/ug/rules-for-using-variable-length-argument-lists-for-code-generation.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.