find a Nan in column of cell array and delete the row
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi everyone, I have a cell array (1152,4) In this cell array I would like see if in each column 1,2,3,4 if there is a Nan, if there is a Nan I would like delete the row.
For that I try to use : cellfun(@isnan,newTab,'UniformOutput',false) and it sends a matrix with logical value (0/1), how can I delete row if there is a 1 in my matrix?
Thank you
댓글 수: 0
답변 (5개)
Alex
2013년 12월 5일
편집: Alex
2013년 12월 5일
댓글 수: 1
sixwwwwww
2013년 12월 5일
no it will not work because if NaN will appear in 2nd or 3rd or 4th column then that row will not be deleted because we are not getting indices for those rows. I edited my answer which has small mistake. So you can accept my edited question. I correct it
Jos (10584)
2013년 12월 5일
If your cell array C has only numbers or NaNs, this will do the job
C = {1 2 3 4 ; 11 12 NaN 14 ; 21 22 23 24}
C(any(isnan(cell2mat(C)),2),:) = []
If your cell array C has a mixture of numbers, char arrays or NaNs, the one-liner above will not work, but this will:
C = {1 2 3 4 ; 'DeleteThisRow' 12 NaN ones(3) ; 21 rand(2) 23 24:29}
C(any(cellfun(@(x) numel(x)==1 & isnumeric(x) && isnan(x),C),2),:) = []
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!