Index exceeds the number of array elements

1 visualización (últimos 30 días)
Enrico Robinson
Enrico Robinson el 20 de Sept. de 2021
Comentada: Enrico Robinson el 20 de Sept. de 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?

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by