# I have a vector where the end is padded with NaN. How to index where real numbers end and where NaNs begin

3 vues (au cours des 30 derniers jours)
Joanne Hall le 2 Mar 2023
Commenté : Joanne Hall le 2 Mar 2023
Dear Matlab,
Attached is sample data with a row vector.
The row vector is an averaged EEG signal and starts with real numbers and at some point, the real numbers end and the NaNs begin. I want to find where (what column) the NaNs start so that I can trim the NaNs and just have a vector of real number values. Please help/advice.
Joanne
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

the cyclist le 2 Mar 2023
Modifié(e) : the cyclist le 2 Mar 2023
Here are two methods of finding the last index that is not NaN:
% Method 1
lastNonNanIndex1 = sum(not(isnan(c)))
lastNonNanIndex1 = 185934
% Method 2
lastNonNanIndex2 = find(not(isnan(c)),1,"last")
lastNonNanIndex2 = 185934
But if you don't need the index, and just want to trim it, then
c(isnan(c)) = []; % Trims the NaN values from the vector
numel(c) % Show the length of the new vector
ans = 185934
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Joanne Hall le 2 Mar 2023
I tried the last one - worked like a charm - thank you so much!!!

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by