MATLAB function block loading code at runtime of Simulink

I would like to have some file,, myfunc.min my MATLAB path and somehow load its contents into the MATLAB function block automatically just before starting the simulation. Thus, I can use an external editor to write these built-in functions, the version manages them separately as independent files, etc.

Is there a way to achieve this programmatically?

My initial attempt was to try to access the contents of a function block using something like get_param, but I cannot get read and write access to the code itself.

+3
source share
3 answers

MATLAB Function , (. SO):

load_system('eml_lib');
libname = sprintf('eml_lib/MATLAB Function');
add_block(libname,'myModel/myBlockName');

API Stateflow:

sf = sfroot();
block = sf.find('Path','myModel/myBlockName','-isa','Stateflow.EMChart');
block.Script = 'Your code goes here';

. MATLAB.

+2

, m , . :

( ) → → ( , m)

InitFcn . :

( ) → → → InitFcn , InitFcn, , myfunc(); .

" " .

+1

, , , .

0

All Articles