フィルターのクリア

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 Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by