Array indices must be positive integers or logical values error
19 views (last 30 days)
Show older comments
Hope Damogbe
on 16 Mar 2019
Edited: Hope Damogbe
on 16 Mar 2019
I am trying to perform the following on MATLAB

However, I keep getting the error which says "Array indices must be positive integers or logical values error"
Please help. Here's my code:
nT=0
for n=0:10000 %part 5
beta=alpha*sqrt(1-((2*n)/N-1)^2);
if abs(n)<= (N-1)/2
syms k x
Ibeta=1+symsum((((1/factorial(k))*(beta/2)^k)^2),k,1,Inf)
Ialpha=1+symsum((((1/factorial(k))*(alpha/2)^k)^2),k,1,Inf)
wk(nT)=Ibeta/Ialpha
nT=nT+1;
else
wk(nT)=0
nT=nT+1;
end
n=n+1;
end
THIS IS THE ERROR I GET:
Array indices must be positive integers or logical values.
Error in DSPproj (line 25)
wk(nT)=Ibeta/Ialpha
0 Comments
Accepted Answer
Walter Roberson
on 16 Mar 2019
You initialize nT to 0. You access wk(nT) but nT is still 0.
You need to move the increments of nT to before you use nT as indices.
2 Comments
Walter Roberson
on 16 Mar 2019
Yes, but array indices start at 1 in MATLAB. 0 is not a valid index in MATLAB.
More Answers (0)
See Also
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!