Export Matlab function block to referenced file

8 次查看(过去 30 天)
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

回答(1 个)

Pavan Guntha
Pavan Guntha 2021-8-30
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!

类别

Help CenterFile Exchange 中查找有关 Create Large-Scale Model Components 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by