Varying input into a transfer function in simulink

1 Ansicht (letzte 30 Tage)
Jake
Jake am 10 Jan. 2023
Beantwortet: Paul am 11 Jan. 2023
I want to vary a constant inside a transfer function in simulink. For example the transfer function could be: 1/(AS+1) where A is the varying constant. Then I want it to store the ouptut of each value in an array.
I tried doing this in Matlab with the following code:
G = zeros(10,2);
for i = 1:1:10
A = i;
out = sim('');
values1 = out.simout.values(:,1);
values2 = out.simout.values(:,2);
G = values2.*values1;
end
However, this code does not store every value of G that is calculated, and does not allow for A to be non integer values like i = 1:0.01:10.
Is there any way to do this?

Akzeptierte Antwort

Paul
Paul am 11 Jan. 2023
Hi Jake,
It looks like you're tring to vary the value of A between runs, not during a run.
In this case, I think you want something like this:
Avals = 1:.01:10;
G = cell(numel(Avals),1);
for i = 1:numel(Avals)
A = Avals(i);
out = sim('');
values1 = out.simout.values(:,1);
values2 = out.simout.values(:,2);
G{i} = values2.*values1; % use a cell array here if values can have a different number of rows from one run to the next
end

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown 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