change code of a matlab function within a simulink model with a script

1 次查看(过去 30 天)
I use the find_system command within a Matlab script to get the identifier of a Matlab function within a Simulink model. Now I want to change the sourcecode of this Matlab function out of the Matlab script. I tried set_param(identifier,parameter) but I can't find the rigth parameter. Which command do I have to use?

回答(1 个)

Brandon Eidson
Brandon Eidson 2017-1-6
Hey Bernhard, I am not immediately aware of a way to accomplish precisely what you are asking. I can think of two close alternatives.
1) You may could use a "Level-2 MATLAB S-Function" block and programmaticaly change the MATLAB S-Function to which it was referring (the Dialog Parameter "FunctionName").
set_param(handleToBlock, 'FunctionName', 'newFunction');
This would require all the S-functions to have the same input and output properties. You can execute the command "sfun_demos" to view several examples of using S-functions.
2) You could use a "Variant Subsystem" block. Inside it could be several subsystems, each with a MATLAB function block inside. You could then programmatically update the conditions to vary which subsystem was enabled. You can read more about variant subsystems at the documentation linked to below.
  1 个评论
Bernhard Baier
Bernhard Baier 2017-1-15
Hi Brandon, Sorry for the late response.
No this is not what I wanted.
I have a script that generates Matlab code depending on data loaded by the user via a mat file. If the user updates this mat file I want to automatically update the code of a Matlab function inside a Simulink Model. Therefore I thougth I could use the set_param function but I think there has to be another solution.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by