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

1 Ansicht (letzte 30 Tage)
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?

Antworten (1)

Brandon Eidson
Brandon Eidson am 6 Jan. 2017
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 Kommentar
Bernhard Baier
Bernhard Baier am 15 Jan. 2017
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by