How to change simulink variable from matlab script?
111 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
David Boelke
am 10 Okt. 2022
Beantwortet: David Boelke
am 21 Okt. 2022
This is a simplified example of the problem I am facing.
What I have:
I have a simulink model (PT1.slx):
And I have a matlab script (control.m):
% clean up
clear
close all
clc
% use simulink
set_param('PT1/K','Value','3');
out=sim('PT1');
% plot results
plot(out.output);
hold on
plot(out.input);
The script, can set the value of a constant, start the model and plot the output, neat!
What I want:
I want to be able to control the value inside my transfer function from my matlab script, for instance this:
What I have tried:
I have found out, that you can't control values like the one circled in red from datalines, for numeric reasons. But I can create a 'variable' for this value and control it from the 'model explorer', but how I can control my variables from a matlab script I do not know.
I have read through the 'set_param' help to see if it could be used for my purposes, but it seems I need a different tool.
I have searched around and found forum entries like
this: https://de.mathworks.com/matlabcentral/answers/426069-setting-simulink-parameter-values-from-script
It talks about how someone can control 'simulink parameters', I don't think that is the same as a 'variable'.
0 Kommentare
Akzeptierte Antwort
Benjamin Thompson
am 10 Okt. 2022
Here is a link to documentation on working with model workspace variables:
Weitere Antworten (2)
Fangjun Jiang
am 10 Okt. 2022
Bearbeitet: Fangjun Jiang
am 10 Okt. 2022
You can use set_param().
block='PT1/Transfer Fcn';
a=get_param(block,'Denominator')
b=eval(a)
b(2)=1.5
c=mat2str(b)
set_param(block,'Denominator',c);
a =
'[1 1 0]'
b =
1 1 0
b =
1.0000 1.5000 0
c =
'[1 1.5 0]'
Siehe auch
Kategorien
Mehr zu Programmatic Model Editing 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!