Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing custom MATLAB functions in Simulink

I would like to use a custom MATLAB function in Simulink. So far I have done it by placing an embedded MATLAB function block. However, if the custom function contains another custom function the compile process fails.

Here is the example of function I am trying to embed in the simulation:

function [c, d, iterationsCount] = decodeLDPC(y, H, variance)
Lci = initializeLq(y, H, variance);
Lr = getLr(Lci);
[Lq, c] = getLq(Lci, H, Lr);
iterationsCount = 1;

while(sum(mod(c * H', 2)) ~= 0)
    Lr = getLr(Lq);
    [Lq, c] = getLq(Lq, H, Lr);
    iterationsCount = iterationsCount + 1;
end;
G = getGeneratorMatrix(H);
d = c/G;

where initializeLq and getLr are custom functions as well.

Is there a method to implement the above function in the simulation?

like image 949
Niko Gamulin Avatar asked Apr 28 '10 13:04

Niko Gamulin


People also ask

How do I add MATLAB code to Simulink?

Make sure your existing MATLAB function is on your MATLAB path. Then, add a MATLAB Function block to your model with the same inputs and outputs as your existing MATLAB function, and then simply call your function from inside the MATLAB Function block.

How do I add custom blocks in Simulink?

Placing Custom Blocks in a LibraryIn the Simulink® Editor, in the Simulation tab, select New > Library. From the User-Defined Functions library, drag a Level-2 MATLAB S-Function block into your new library. Save your library with the filename saturation_lib .


1 Answers

You need to use the command eml.extrinsic to call any external MATLAB functions from an EML block. For example, you can put this at the top of your EML function,

eml.extrinsic('getLr', 'initializeLq');

to allow those functions to be called. For more information, see the documentation

like image 134
MikeT Avatar answered Sep 29 '22 09:09

MikeT