Index exceeds the number of array elements (1). Error in sym/subsref (line 909) R_tilde = builtin('s​ubsref',L_​tilde,Idx)​; Error in newuntitled2 (line 17) r(k)=r(k)+​(y(i)*conj​(y(i+k-1))​); How to solve this error?

1 view (last 30 days)
clc;
clear all;
close all;
n=16;
pi=sym(pi)
for i=1:n
x = (pi/n)*(i-1)*(i-n-1)
y=x-2*pi*fix(x/(2*pi))
if(y<0)
y=y+(2*pi)
end
end
disp(y)
r=zeros(1,n);
for k=1:n
for i=1:n-k+1
r(k)=r(k)+(y(i)*conj(y(i+k-1)));
end
end
disp(r);
b=sort(r,'descend');
max=r(2);
s=max/r(1);
p=20*log10(s)
f=(rssq(r))^2-r(1)^2
h=(2*f)/r(1)
l= 10*log10(h)

Answers (1)

Walter Roberson
Walter Roberson on 28 May 2021
In your for i loop you overwrite all of y every iteration. You should be writing to y(i)

Categories

Find more on Electrical Block Libraries in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!