Export Matlab function block to referenced file

6 visualizzazioni (ultimi 30 giorni)
Steffen Fock
Steffen Fock il 3 Mag 2021
Risposto: Pavan Guntha il 30 Ago 2021
Hello Community,
I am trying to create a Simulink projekt structure in which as many subsystems as possible exist in the form of individual files. Among other things, individual Matlab functions should be able to be opened directly via the folder system without the detour via the Simulink model. One possibility for this are the Interpreted Matlab functions. However, I like the advantages of a Matlab function block. Matlab function blocks can be opened from the Simulink project and the structure of these blocks is similar to other Simulink blocks (multiple inputs and outputs, and a similar user interface).
So i would be interested if it is possible to save Matlab function blocks as an external file or if there is another way to integrate a Matlab function, like described above, into Simulink?
Thank you

Risposte (1)

Pavan Guntha
Pavan Guntha il 30 Ago 2021
Hello Steffen,
I understand that the requirement here is to have a MATLAB function saved in a '.m' file and also exploit the advantages of MATLAB Function block in Simulink. A possible workaround to solve this issue is illustrated below:
1) Create a '.m' file contatining the function.
2) Call the function within MATLAB Function block in Simulink.
The following example illustrates this idea:
Create a MATLAB file 'addMul.m':
function [A, M] = addMul(x,y)
A = x + y;
M = x*y;
end
Now, call this function within the MATLAB Function block as follows:
function [A,M] = fcn(x,y)
[A, M] = addMul(x,y);
The corresponding MATLAB Function block looks as follows:
By doing so, you could meet both of your requirements.
Hope this helps!

Categorie

Scopri di più su Create Large-Scale Model Components in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by