How do I fix "Index exceeds the number of array elements"?
Show older comments
n = 0:49;
x1 = 2*sin(3*(9*pi*n/50 + 3*pi/50));
% Determine period and plot 5 periods
N = length(n);
period = N;
while(period <= 2*N)
if(x1(1:period) == x1(period+1:2*period))
break;
end
period = period + 1;
end
fprintf("Period of x1 = %d\n", period);
figure;
stem(n, x1);
hold on;
for i = 1:4
stem(n + i*period, x1);
end
hold off;
title('x1');
xlabel('n');
ylabel('x1[n]');
Answers (1)
Well, period=50 so x1(period+1:2*period) is the same as x1(51:100). Since x1 has length 50, indexing it from 51:100 won't work.
n = 0:49;
x1 = 2*sin(3*(9*pi*n/50 + 3*pi/50));
% Determine period and plot 5 periods
N = length(n);
period = N
I=(period+1:2*period)
length_x1 = length(x1)
x1(period+1:2*period)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!