index must be a positive integer or logical.

1 view (last 30 days)
Tom Cieslewicz
Tom Cieslewicz on 1 May 2016
Answered: John BG on 1 May 2016
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)))

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 1 May 2016
Edited: Azzi Abdelmalek on 1 May 2016
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 on 1 May 2016
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

Community Treasure Hunt

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

Start Hunting!