Export Matlab function block to referenced file
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Pavan Guntha
on 30 Aug 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!
0 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!