1

I have a fine tuned algorithm in MATLAB that operates on matrices (ofcourse). I've used matlab coder to generate c code for this algorithm and it works as expected.

Here's a function call that I used in Matlab

x = B/A 

wherein

  • B is of size 1*500 (rows * columns)
  • A is of size 10*500
  • x, the result is of size 1*10

When this is converted into C source using Matlab Coder. I noticed that the function definition accepts parameters that are same as above sizes.

void myfunction(const double B[500], const double A[5000], double x[10])

For prototype and testing purposes this seems okay. However, in production I prefer to have this function be used for different sizes too. For example 100 instead of 500 in above mentioned variables should also work. How can I remove dependence of matrix dimensions in my algorithm ?

Additionally, there are few lines of code that use hard coded integers. For example, there is code like

if (rankR <= 1.4903363393874656E-8)
// Some internal function calls
else
// Usage of standard sqrt

or

500.0 * fabs(A[0]) * 2.2204460492503131E-16

Could any one explain what are these hard coded integers ? Are these generated from the test data that I've used in MATLAB ?

1 Answer 1

1

If the function call you refer to is the entry-point function, you can define the size when setting up Coder. The simplest way to run the Coder is using the GUI from the 'Apps' menu inside MATLAB (or type 'coder' at the console). After specifying the entry-point function, step 2 is to define the type and size for each of the input variables.

For each dimension of your input variable (there can be more than 2 if necessary), you can specify the:

 n  - dimension is exactly n long
:n  - dimension is up to n long
inf - dimension is unbounded

If the function call is not the entry-point function, and is buried inside your code (or if you are running the codegen function from the console), you can explicitly define variables as being of varying size:

coder.varsize('myVariableName');

Bear in mind that some functions can only be used (with Coder) with fixed-sized inputs.

Fuller description here: http://uk.mathworks.com/help/fixedpoint/ug/defining-variable-size-data-for-code-generation.html#br9t627

Not sure about the random constants unfortunately.

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.