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

1 回表示 (過去 30 日間)
Felicia DE CAPUA
Felicia DE CAPUA 2022 年 11 月 17 日
コメント済み: Felicia DE CAPUA 2022 年 11 月 17 日
Hi everyone,
I have a problem with my code.
This is my code:
plot_power = [872 1016];
time_power = plot_power(1):bin:plot_power(2);
mean_value_data_smooth_1 = mean_value_data_smooth_1.';
mean_value_data_smooth_2 = mean_value_data_smooth_2.';
spectrum_1 = mean_value_data_smooth_1(time_power);
spectrum_2 = mean_value_data_smooth_2(time_power);
the time power is a vector 1x15, while the spectrum_1 and spectrum_2 are a vectors 272x1.
The error is: Index exceeds the number of array elements. Index must not exceed 272.
I don't understand. How can I resolve this???
Thank you so much
  2 件のコメント
Torsten
Torsten 2022 年 11 月 17 日
編集済み: Torsten 2022 年 11 月 17 日
What is
bin
?
What is
size(mean_value_data_smooth_1)
and
size(mean_value_data_smooth_2)
?

サインインしてコメントする。

回答 (2 件)

David Hill
David Hill 2022 年 11 月 17 日
What are you trying to do? You cannot index into mean_value_data_smoth with a value greater than its size (272). You are indexing into it with values from 872 to 1016. If you tell us what you are trying to do, big picture, we might be able to help.
  1 件のコメント
Felicia DE CAPUA
Felicia DE CAPUA 2022 年 11 月 17 日
I need to try the correlation about spectrum_1 and spectrum_2 bewteen this time series (namely time_power).

サインインしてコメントする。


Torsten
Torsten 2022 年 11 月 17 日
mean_value_data_smooth_1 and mean_value_data_smooth_2 only have 272 elements.
Thus the values of the array elements of "time_power" in the assignments
spectrum_1 = mean_value_data_smooth_1(time_power);
spectrum_2 = mean_value_data_smooth_2(time_power);
must lie between 1 and 272.
But they lie between 872 and 1016 by setting
plot_power = [872 1016];
time_power = plot_power(1):bin:plot_power(2);
This will throw the error that the indices of mean_value_data_smooth_1 and mean_value_data_smooth_2 exceed 272.
  7 件のコメント
Torsten
Torsten 2022 年 11 月 17 日
Then you must find the index range (between 1 and 272) in mean_value_data_smooth_1 and mean_value_data_smooth_2 that corresponds to the time range (between 872 and 1016).
Felicia DE CAPUA
Felicia DE CAPUA 2022 年 11 月 17 日
exactly :(

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by