Effacer les filtres
Effacer les filtres

Removing NaN from cell array

97 vues (au cours des 30 derniers jours)
Thulasi Durai Durai Samy
Thulasi Durai Durai Samy le 28 Juin 2012
I have cell array which ends with NaN as last row
'Mat Name' 'MAT Type' 'E1'
'GFRP' 'GFRP' 'GFRP'
'CFRP' 'CFRP' 'CFRP'
'KFRP' 'KFRP' 'KFRP'
'SCDB' 'SCDB' 'SCDB'
'ABCD' 'ABCD' 'ABCD'
[NaN] [NaN] [ NaN]
How to remove the NaN from the last row of cell array
thanks in advance

Réponse acceptée

Honglei Chen
Honglei Chen le 28 Juin 2012
Modifié(e) : Honglei Chen le 28 Juin 2012
x = {'xy','yz',nan}
x(cellfun(@(x) any(isnan(x)),x)) = []
  8 commentaires
Honglei Chen
Honglei Chen le 28 Juin 2012
cellfun will loop each cell for you to check whether a cell is nan or not, but it does not preserve the dimension. So you need to reshape it back at the end.
Jan
Jan le 28 Juin 2012
Another approach, which remove all non-strings: x = x(cellfun('isclass', x, 'char'))

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by