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일

4 개 추천

x = {'xy','yz',nan}
x(cellfun(@(x) any(isnan(x)),x)) = []

댓글 수: 8

Thulasi Durai Durai Samy
Thulasi Durai Durai Samy 2012년 6월 28일
Hello Thanks for your response i tried this command but the following error occurred
raw(cellfun(@isnan,raw)) = [] ??? Error using ==> cellfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false.
try:
x(cellfun(@isnan,x,'UniformOutput',false))
Honglei Chen
Honglei Chen 2012년 6월 28일
I've updated the answer
Its works for the array x which you shown but for the cell array
'Mat Name' 'MAT Type' 'E1'
'GFRP' 'GFRP' 'GFRP'
'CFRP' 'CFRP' 'CFRP'
'KFRP' 'KFRP' 'KFRP'
'SCDB' 'SCDB' 'SCDB'
'ABCD' 'ABCD' 'ABCD'
[NaN] [NaN] [ NaN]
its is not working, kindly help
Honglei Chen
Honglei Chen 2012년 6월 28일
Add
reshape(x,[],3)
after you run the command in my answer
Thulasi Durai Durai Samy
Thulasi Durai Durai Samy 2012년 6월 28일
!!wonderfull!! wow its work well, what is the logic behind it
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개)

카테고리

태그

Community Treasure Hunt

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

Start Hunting!

Translated by