Index exceeds the number of array elements. Index must not exceed 272.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
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.
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
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).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!