Index exceeds the number of array elements

1 vue (au cours des 30 derniers jours)
Enrico Robinson
Enrico Robinson le 20 Sep 2021
Commenté : Enrico Robinson le 20 Sep 2021
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?

Réponse acceptée

Sargondjani
Sargondjani le 20 Sep 2021
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 commentaire
Enrico Robinson
Enrico Robinson le 20 Sep 2021
Thank you for the support you solution has resolved the matter. I completely forgot about the index wise divison (./).

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by