MATLAB function in External mode

1 view (last 30 days)
Mohamed  Ahmeid
Mohamed Ahmeid on 13 Aug 2015
Answered: Walter Roberson on 13 Aug 2015
I work on TI C2000 in external mode, in the model I'm running on the target I have MATLAB function in the Simulink model, is there any particular settings for this function to perform on the target in the same way it works in Simulink in normal mode?

Answers (1)

Walter Roberson
Walter Roberson on 13 Aug 2015
If you have MATLAB Coder and Simulink Coder then for a restricted set of routines, C or C++ code can be generated for use on the C2000. You need to use a MATLAB Function Block (I believe). You will need to rewrite the code in some ways. One of the parts that is needed most often is to declare the size of the variables, as C is not as flexible about dynamic sizing of variables (and also because when you are on an embedded processor you need certainty about the maximum memory used.) See http://www.mathworks.com/help/fixedpoint/ug/defining-variable-size-data-for-code-generation.html
Coder will try to determine the size of the outputs based upon the code. However if you call any MATLAB routines, it may not be able to predict the size that is going to be returned. For this reason if your output depends upon calling a MATLAB routine, it is important that you add an extra assignment statement before the real assignment, where the assignment statement assigns an explicit size to the variable. For example,
y = zeros(1,u(3),'single'); %assign something of an obvious size!
y = sin(single(linspace(u(1), u(2), u(3)))); %then you can assign something where the size is not as clear

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!