필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Felicia DE CAPUA
Felicia DE CAPUA 2022년 11월 5일
편집: Torsten 2022년 11월 12일
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
Jan
Jan 2022년 11월 11일
@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 2022년 11월 12일
편집: Torsten 2022년 11월 12일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2022년 11월 8일
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.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by