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 ExchangeMatrix 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