Matrix index is out of range for deletion
2 views (last 30 days)
i cant find a helpful solution for this error:
Matrix index is out of range for deletion.
If I run the selection again often times it works and deletes the values.
Here my code and attached the matrix.
if isnan(Zeit_Flutende_5000_BA_neu(i,:))== 1;
Star Strider on 27 Jun 2022
This is the problem when deleting elements in a loop, although there could be a different problem, such as addressing a column vector with row vector subscripting references.
It is better to use logical indexing to eliminate all the NaN values at once, without looping:
LD = load('Zeit_Flutende_5000_BA_neu.mat');
Zeit_Flutende_5000_BA = LD.Zeit_Flutende_5000_BA;
i = 1;
Zeit_Flutende_5000_BA_nonan(:,i) = Zeit_Flutende_5000_BA(~isnan(Zeit_Flutende_5000_BA(:,i))); % Logical Indexing
Zeit_Flutende_5000_BA_nonan(:,i) = rmmissing(Zeit_Flutende_5000_BA); % 'rmmissing'
These both give the same result (a 612x1 column vector with no NaN values). This is a column vector, not a row vector, so the original subscript references were incorrect. These are now correct.
The rmmissing function was introduced in R2016b. Use it if you have it, since it (and its friends) make prolbems like this easier.