Varying input into a transfer function in simulink

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?

 Réponse acceptée

Paul
Paul le 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

Plus de réponses (0)

Catégories

En savoir plus sur Simulink dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by