index must be a positive integer or logical.

Im trying to plot data points and i keep getting "Attempted to access w(1.79867e-06); index must be a positive integer or logical."
I have no idea how to fix it. Any help would be great.
CODE:
r = 1.798*10^-3; c = 0.001*10^-6; l = 3.234*10^-9; f = logspace(6,9,4000); w = 2*pi*f; h = 1/(1+i*(w(l/r)-(1/(w*r*c))));
semilogx(f,20*log(abs(h)))

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 1일
편집: Azzi Abdelmalek 2016년 5월 1일

0 개 추천

Use ./ instead of / and also you a missed a multiplication operator *
h = 1./(1+i*(w*(l/r)-(1./(w*r*c))));
John BG
John BG 2016년 5월 1일

0 개 추천

the main problem comes from
w(l/r)
Subscript indices must either be real positive integers or logicals.
You are trying to reach element 0, because from your script, l=0, r=0, and here MATLAB assumes 0/0=0 but in MATLAB vectors start with index 1, not 0, regardless of the size and amount of dimensions of the matrix.
If you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2016년 5월 1일

답변:

2016년 5월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by