Index exceeds the number of array elements (8000).

Error in autodecoder_freq (line 35)
x = [signal(950:1450), signal(2100:2600), signal(3150:3650), signal(4200:4700), signal(5250:5750), signal(6350:6850), signal(7400:7900), signal(8500:9000), signal(9600:10100),
signal(10600:11100), signal(11750:12250), signal(12800:13300)];
N = 512;
% aproximate frequency interval
lowfreq = [650 733 811 897 1000];
highfreq = [1000 1273 1407 1515];
% tone frequency dictionaries
dic_low = [697 770 852 941];
dic_high = [1209 1336 1477];
% digited numbers
tele = [1,2,3; 4,5,6; 7,8,9; 11,0,12]; % '*' = 11; '#' = 12
[signal, fs] = audioread('DialedNumber.wav');
fN=fs/2; % Nyquist frequency
playout = audioplayer(signal,fs);
play(playout);
figure(1)
plot (signal)
title('Signal')
xlabel('Time')
ylabel('Magnitude')
% 12 column matrix of the signal (stable part of the signal segments)
x = [signal(950:1450), signal(2100:2600), signal(3150:3650), signal(4200:4700), signal(5250:5750), signal(6350:6850), signal(7400:7900), signal(8500:9000), signal(9600:10100), signal(10600:11100), signal(11750:12250), signal(12800:13300)];

1 Comment

% aproximate frequency interval
lowfreq = [650 733 811 897 1000];
highfreq = [1000 1273 1407 1515];

Sign in to comment.

Answers (1)

The error message indicates that your code is attempting to access elements in the array that do not exist. This typically happens when the indices specified are beyond the length of the array.
To resolve this issue, you can first check the length of the signal array. You can do this by adding a line of code to display the length of signal:
disp(['Length of signal: ', num2str(length(signal))]);
Once you know the length of the signal, ensure that all the indices you are trying to access are within this range.
You can find more information about “length” below:

Tags

Asked:

on 9 Apr 2021

Commented:

on 7 Mar 2025

Community Treasure Hunt

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

Start Hunting!