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 CenterFile Exchange에서 Creating 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