Removing NaN from cell array
조회 수: 97 (최근 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
댓글 수: 0
채택된 답변
Honglei Chen
2012년 6월 28일
편집: Honglei Chen
2012년 6월 28일
x = {'xy','yz',nan}
x(cellfun(@(x) any(isnan(x)),x)) = []
댓글 수: 8
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
2012년 6월 28일
Another approach, which remove all non-strings: x = x(cellfun('isclass', x, 'char'))
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!