Index exceeds the number of array elements

1 回表示 (過去 30 日間)
Enrico Robinson
Enrico Robinson 2021 年 9 月 20 日
コメント済み: Enrico Robinson 2021 年 9 月 20 日
I have been given the task to create a vector f with 1000 values, logarithmic spaced. The smallest value for f must be 10; the biggest vale for f must be 100000. I have been provided a diagram of a circuit and the following transfer function, H f( ), applies:
f = logspace(10,100000,1000);
w = 2*pi*f
R = 10
L = R/2000*pi
C = 1/2000*pi*R
z1 = 1/1i*w*C
z2 = R + 1i*w*L
H(f) = (z2(f)/(z1(f) + z2(f)))
mod = abs(H(f))
semilogx(f,mod)
I am trying to make a plot of the modulus of the transfer function H f( ) as a function of f . The horizontal scale of the plot must be logarithmic.
The line of code that is giving the the error is H(f) = (z2(f)/(z1(f) + z2(f)))
Can someone please help me understand where im going wrong?

採用された回答

Sargondjani
Sargondjani 2021 年 9 月 20 日
The argument in brackets should be an index number, so for example:
x = 1:10; %a 1 x 10 vector
for ix = 1:size(x,2);
f(ix) = x(ix)^2;
end
Which could be achieved also with .^
f = x.^2;
In your case f is the vector, and consequently all your other variables. To calculate H:
H = z2./(z1 + z2)
modH = abs(H)
  1 件のコメント
Enrico Robinson
Enrico Robinson 2021 年 9 月 20 日
Thank you for the support you solution has resolved the matter. I completely forgot about the index wise divison (./).

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by