Removing NaN from cell array

115 次查看(过去 30 天)
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

采纳的回答

Honglei Chen
Honglei Chen 2012-6-28
编辑:Honglei Chen 2012-6-28
x = {'xy','yz',nan}
x(cellfun(@(x) any(isnan(x)),x)) = []
  8 个评论
Honglei Chen
Honglei Chen 2012-6-28
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 2012-6-28
Another approach, which remove all non-strings: x = x(cellfun('isclass', x, 'char'))

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Operations and Transformations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by