Index exceeds the number of array elements. Index must not exceed 620757.

1 visualización (últimos 30 días)
Hi everyone,
this is my code:
bin_data1 = 1:(bin*new_fs):size(data_1,1)-1;
time_1 = (1:bin:(size(data_1)/new_fs))-1;
step = data_1(bin_data1:bin_data1+(bin*new_fs)-1);
[S_1,f_1] = mtspectrumc(step,params); % compute spectrum
value_data_1 = S_1(find((f_1>=2 & f_1<=150)==1));
value_data_1_smoothed=smoothdata(value_data_1,'gaussian',30);
value_data_1_smoothed_bin = value_data_1_smoothed(bin_data1);
plot(time_1,value_data_1_smoothed_bin,'r');
title('2-150 Hz'); xlable('Time (s)'); ylabel('Power (dB)');
When I do running the script, it appears a problem:
Index exceeds the number of array elements. Index must not exceed 620757.
But what is the index?
  24 comentarios
Jan
Jan el 11 de Nov. de 2022
@Torsten: Thanks for removing the misplaced comma from my comment.
As non-native speaker I'm aware that my spelling has a potential for improvements. I takes some time to check, what has been modified in an edited comment. Therefore I appreciate fixing typos, if it really improves the comprehensibility of my contributions.
Torsten
Torsten el 12 de Nov. de 2022
Editada: Torsten el 12 de Nov. de 2022
Thought I could do it unnoticed :-)
But although I'm from Germany (like you ?) where the comma in front of "that" is obligatory, it took some time before I understood what you meant in your comment. So I took the risk to edit away the comma.

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 8 de Nov. de 2022
What is element number 11 of the following vector?
x = 1:10
The answer to the question is "it doesn't exist." In situations where MATLAB asks that kind of question, the way it says "it doesn't exist" is to throw the error you're receiving.
To determine the root cause of this failure, set a breakpoint on the line of code where you receive this error then run your code. [If this code is in a loop and this error occurs only after a few iterations, set an error breakpoint as described in the Error Breakpoints section on that documentation page instead.] When MATLAB reaches the breakpoint, look at the size of the variable into which you're indexing and the max of the arrays you're using as indices.
Once you've confirmed that you're in this "asking for the 11th element of a 10 element vector" scenario, look backwards in your code to see where you're potentially changing the size or values of either of the arrays involved in that indexing operation. This could involve setting breakpoints on earlier lines of your code and stepping through line-by-line looking at those arrays in the Workspace Browser to detect when those arrays change.

Categorías

Más información sobre Descriptive Statistics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by