Index exceeds the number of array elements

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by