Filter löschen
Filter löschen

Replace NaN values with blanks

14 Ansichten (letzte 30 Tage)
Subhiksha
Subhiksha am 24 Sep. 2013
Bearbeitet: Stephen23 am 29 Jun. 2018
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 24 Sep. 2013
[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 am 24 Sep. 2013
Samyukhta , please if you want to comment an answer, click on [comment on this answer]

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 24 Sep. 2013
Bearbeitet: Jan am 24 Sep. 2013
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 Kommentare
Subhiksha
Subhiksha am 24 Sep. 2013
It worked perfectly fine:):)
Thank you.
Stephen23
Stephen23 am 29 Jun. 2018
Bearbeitet: Stephen23 am 29 Jun. 2018
@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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 24 Sep. 2013
A={nan 1 2 nan 3 'r'}
A(cellfun(@isnan,A))={''}

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by