How to remove NaN value from front part (first column) of raw matrices.

2 vues (au cours des 30 derniers jours)
Yared Daniel
Yared Daniel le 28 Mai 2021
Modifié(e) : Yared Daniel le 29 Mai 2021
I have multiple files that contain row matrices. Some of the row metrics starts with number and some starts with missing value (NaN).
What I need is the row matrices to start with a number (the number have to be the one which comes after removing the all the NaN values that preceding it)
For instance x = [NaN NaN 89 87 45 90 NaN 100 52 Nan]
The returned x_new has to be x = [ 89 87 45 90 NaN 100 52 NaN]. NaN in the middle or end of the row remains as it was.
In addition the algorithm has to skip the file that contains row data which begins with number. I have attached the files
Thank you for all our contribution in advance

Réponse acceptée

Jonas
Jonas le 28 Mai 2021
Modifié(e) : Jonas le 28 Mai 2021
can't check your files at the moment, but it should be something like that:
for fileNr=1:6
load(['S' num2str(fileNr)],'x')
if ~isnan(x(1))
continue;
else
x(1)=[]; % first NaN removal
end
while isnan(x(1)) % if there are more NaN entries at the beginning
x(1)=[];
end
% do stuff with your clean vector
end
  1 commentaire
Yared Daniel
Yared Daniel le 29 Mai 2021
Modifié(e) : Yared Daniel le 29 Mai 2021
Thank you so much, It solved my problem perefectly

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by