Replace NaN values with blanks

조회 수: 2 (최근 30일)
Subhiksha
Subhiksha 2013년 9월 24일
편집: Stephen23 2018년 6월 29일
Hello all,
I need to replace the NaN values with a blank space in either a matrix or cell array. What should I do?? On trying the below code with cell array, I got the following error:
a(cellfun(@isnan,a)) = {[]}; Error: Function name must be a string.
I am using Matlab 7.0.1 (R14).
How should I give the isnan function???
Thanks in advance for the help.
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 24일
[Samyukhta commented]
Hello Ilham Hardy and Azzi Abdelmalek ,
I get the same error , Function name must be a string.
What should I do???? How am I supposed to give @isnan()???
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 24일
Samyukhta , please if you want to comment an answer, click on [comment on this answer]

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

채택된 답변

Jan
Jan 2013년 9월 24일
편집: Jan 2013년 9월 24일
R14 is very old now. I'm not sure if cellfun accepted function handles freely in this version. But you can emulate this simply by a loop:
for k = 1:numel(C)
if isnan(C{k})
C{k} = '';
end
end
Replacing NaN values by '' in a matrix will not work: All elements of a matrix need to be the same type. While NaN is a double or single, the empty string is a char.
  댓글 수: 2
Subhiksha
Subhiksha 2013년 9월 24일
It worked perfectly fine:):)
Thank you.
Stephen23
Stephen23 2018년 6월 29일
편집: Stephen23 2018년 6월 29일
@Vasishta Bhargava: numeric arrays cannot contain characters, so what you want is not possible. The value 65 is the character encoding number for the letter 'A'. You were told this in response to your earlier comment:
Please stop hijacking other people's threads. You have been given the same information twice now, it will not change if you ask again.

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 24일
A={nan 1 2 nan 3 'r'}
A(cellfun(@isnan,A))={''}
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 24일
In windows command type
isnan
What did you get?

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by