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

3 ビュー (過去 30 日間)
Bernhard Baier
Bernhard Baier 2017 年 1 月 4 日
コメント済み: Bernhard Baier 2017 年 1 月 15 日
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 Center および File ExchangeProgrammatic Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by