How to ignore NaN in a string cell
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi,
I have a cell array called test2 that contains some NaN and strings in each column, see attached image below.
I would like to create a loop where I can loop through test2 and ignore the NaN columns. The issue I am having is NaN characteristic is double and the if statement I created, if (cellfun(@(x) any(isnan(x)),test{i},'UniformOutput',false)), gives this error input#2 expected to be a cell array, was double instead.
Side note: i is the indices, for example i=1:1590.
Any help is very much appreciated.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/748969/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/748969/image.png)
댓글 수: 0
채택된 답변
Sulaymon Eshkabilov
2021년 9월 25일
편집: Sulaymon Eshkabilov
2021년 9월 25일
A simple answer is e.g.:
TEST = test(cellfun('isclass', test, 'char')) % All NANs removed
An alternative solution is e.g.:
test(cellfun(@(test) any(isnan(test)),test)) = []
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!