how to access built in matlab function in simulink?

5 visualizzazioni (ultimi 30 giorni)
Anu  Sri
Anu Sri il 10 Mar 2019
Modificato: Akanksha il 21 Feb 2025
I am trying to make simulink model for image compression algorithm using many builtin matlab functions.the problem is that when i run it simulink is not able to load the built in functions and i have to make separate function for it and attach it there.this is making my model complex and confusing.can anyone help me to fix this problem?

Risposte (1)

Akanksha
Akanksha il 21 Feb 2025
Modificato: Akanksha il 21 Feb 2025
You can use any of the following two approaches to help resolve the query.
  1. MATLAB Function Block Setup:
  • In your Simulink model, drag and drop a MATLAB Function block from the Simulink library. You can find this block under "User-Defined Functions" in the library browser.
  • Double-click the MATLAB Function block to open the "MATLAB Function Block Editor".
  • In the editor, you can write your custom MATLAB code. Here, you can call any built-in MATLAB function as well.
  • Define the inputs and outputs of the function in the MATLAB Function Block Editor. For example, if you want to use a built-in function like“sin, write:
function y = fcn(u)
y = sin(u);
where “u”is the input to the function, and“y”is the output.
2. coder.extrinsicfunction :
Use the "coder.extrinsic" function for any MATLAB functions that are not supported for code generation. This tells Simulink to execute the function in MATLAB rather than generating code for it.
Example:
coder.extrinsic('imresize');
function y = resizeImage(u)
y = imresize(u, 0.5); % Example of resizing an image
end
For more information on the function and its arguments and other properties refer https://www.mathworks.com/help/simulink/slref/coder.extrinsic.html?s_tid=doc_ta
Hope this helps. Thanks.

Categorie

Scopri di più su Modeling in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by