Force element access inside for loop

10 Ansichten (letzte 30 Tage)
Massimo Pesavento
Massimo Pesavento am 28 Apr. 2020
Kommentiert: Tommy am 28 Apr. 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))

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by