Force element access inside for loop

10 vues (au cours des 30 derniers jours)
Massimo Pesavento
Massimo Pesavento le 28 Avr 2020
Commenté : Tommy le 28 Avr 2020
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))

Réponse acceptée

Tommy
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
Massimo Pesavento
Massimo Pesavento le 28 Avr 2020
Thank you so much, indeed that's the cause, I didn't know MATLAB treated them differently.
Have a nice day
Tommy
Tommy le 28 Avr 2020
Fantastic, same to you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by