6

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?

2
  • I think MikeT's answer is correct, but I offer this to you: don't use an embedded MATLAB function block in your model because this block causes the model to run very slowly. Commented Jun 20, 2010 at 19:05
  • If your model is running slowly, you might want to wrap the EML block with a stateflow diagram.This will eliminate the copying of inputs and outputs on each time-step that can make EML functions outside of stateflow diagrams (in older versions of MATLAB, at least) less efficient. Commented Jan 26, 2011 at 13:02

1 Answer 1

1

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

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.