필터 지우기
필터 지우기

remove [NaN] from cell array

조회 수: 9 (최근 30일)
Michiel
Michiel 2015년 4월 14일
댓글: Michiel 2015년 4월 16일
I have large cell arrays in which a couple of entries could not be read from an excel file, since the corresponding places are empty. In my cell array I obtain: [NaN]
now I wish to replace this with an empty string: ''
this is what I tried and got:
>> raw(cellfun(@isnan,raw)) = {''};
Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
>> raw(cellfun(@isnan,raw,'UniformOutput',false)) = {''};
Error using subsindex
Function 'subsindex' is not defined for values of class 'cell'.
suggestions?
  댓글 수: 1
Jan
Jan 2015년 4월 16일
Please post a relevant part of the cell raw such that we can reproduce the problem.

댓글을 달려면 로그인하십시오.

채택된 답변

Titus Edelhofer
Titus Edelhofer 2015년 4월 16일
Hi,
if your raw contains both strings and NaN, you will need to do something like this:
raw(cellfun(@(x) isnumeric(x) && isnan(x), raw)) = {''};
If your raw contains numbers only, I would convert to an array (cell2mat) and then use isnan directly.
Titus
  댓글 수: 1
Michiel
Michiel 2015년 4월 16일
thank you, the first is what I was looking for

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by