Matrix index is out of range for deletion

10 次查看(过去 30 天)
Hi
Im using EEGLAB toolbox for preprocess my data.
one step in my preprocessing is to remove manually some noisy segments of the data.
When Im using the removing function i have no problem at all, but when Im using my code on a multiple subjects i get the error below:
the part of the code which stack when applied on multiple subjects:
any suggestions?

回答(1 个)

Walter Roberson
Walter Roberson 2020-10-28
You have a loop in which you move forward through the loop, deleting entries if some condition matches.
However, every time you delete something, everything after that in the same array "falls down" to fill the hole, sort of like in Tetris. And so all of the positions you had calculated for anything after that become invalid, because the corresponding data entries have moved forward in the array by size corresponding to what you deleted.
The easiest way to fix this kind of problem is not to loop forward deleting as you go, but instead to move backwards deleting as you go. The positions for anything before for deletion point will not be changed by having deleted afterwards, so you do not need to update anything in the positions.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by