Force element access inside for loop
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I'm playing with transfer functions to extract the causal part of one.
However, when I do
z = tf('z',0.001); tfCaus = tf(k0plus, 0.001); % adding the delta@0
for stbIdx = find(abs(p)<1)
tfCaus = tfCaus + r(stbIdx)/ (z-p(stbIdx))^(m(stbIdx));
end
I get an error about the ^ (transfer function) operator failing as the inputs are treated as vectors . In particular the error is
In the expression "M^K", the model M must have the same number of inputs and outputs.
while explicitly requesting the index, doing
tfCaus = tfCaus + r(2)/ (z-p(2))^(m(2))
works as expected. It seems to me that stbIdx isn't properly substituted as scalar at runtime. I've checked and and it's a proper vector.
The same behavior fails when doing
zpk([],p(stbIdx)*ones([m(stbIdx),1]), r(stbIdx))
but the code below works
zpk([],p(2)*ones([m(2),1]), r(2))
0 commentaires
Réponse acceptée
Tommy
le 28 Avr 2020
Is p a column vector?
Notice the difference between the following:
>> for i = 1:3
disp('a')
end
a
a
a
and
>> for i = (1:3)'
disp('a')
end
a
Does it work if you use
for stbIdx = find(abs(p)<1)'
2 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!