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

조회 수: 6 (최근 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 CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by