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

2 views (last 30 days)
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

Answers (2)

David Hill
David Hill on 17 Nov 2022
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 Comment
Felicia DE CAPUA
Felicia DE CAPUA on 17 Nov 2022
I need to try the correlation about spectrum_1 and spectrum_2 bewteen this time series (namely time_power).

Sign in to comment.


Torsten
Torsten on 17 Nov 2022
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 Comments
Torsten
Torsten on 17 Nov 2022
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).

Sign in to comment.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!