Array indices must be positive integers or logical values

Fs=1000
Fc=250
dF=50
Br=.001
A=-20*log(Br)
dw=2*pi*(dF/Fs)
N=floor((A-8)/(2.285*dw)+1)
b=.1102*(A-8.7)
a=(N-1)/2
prompt = 'What is the original value? ';
n = input(prompt)
w = I(b(1-((n-a)/a)^2)^.5)/I(b)
if
n==(N-1)/2
hD=2*Fc
end
else if
n~=(N-1)/2
hD=2*Fc*sin((n-((N-1)/2))*2*pi*Fc)/(n-((N-1)/2))*2*pi*Fc
plot(hD*w,n);
This code is showing "Array indices must be positive integers or logical values". why is it showing this message?

2 Comments

w = I(b(1-((n-a)/a)^2)^.5)/I(b)
Is l a function being invoked or is it an array being indexed?
I was an user defined function. here it is:
function y=I(x);
y=0
for i=0:31
y=y+[(x/2)^i/factorial(i)]^2;
end
end

Answers (1)

This line throws the error:
w = I(b(1-((n-a)/a)^2)^.5)/I(b)
To begin with, ‘I’ is not defined in your code.
That aside, ‘b’ is a scalar, and MATLAB is going to consider ‘(1-((n-a)/a)^2)’ as a subscript reference into it. That may not be an integer, and may not be positive.
You appear be missing several arithmetic operators, most likely multiplication operators. You have to define those and correct your code to elimiinate the problems with it.

This question is closed.

Tags

Asked:

on 9 May 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!