# replace NaN values with numericl values

931 views (last 30 days)
lina on 3 Apr 2014
Commented: madhusmita sahu on 4 May 2020
Hi all,
i have a NaN values in the matrix those i can not importing a numerical values in it the undefined variable error is appear
the question is what should i do to import the numerical matrix into NaN matrix ?

Show 1 older comment
lina on 3 Apr 2014
what should i do to import the numerical matrix into NaN matrix ?
Azzi Abdelmalek on 3 Apr 2014
How your text file looks like?
lina on 3 Apr 2014
nc files those for marine physics not all of variables are apear

Azzi Abdelmalek on 3 Apr 2014
If you want to replace the nan values by 0 for example
A(isnan(A))=0

Show 1 older comment
Abdul Haleem Butt on 16 Nov 2015
what to do if we want to replace nan values by some numeric values i have patient ids like this HC01MI and i want to give some random numeric values to these ids
Javaid Iqbal on 15 May 2018
Thanks a lot sir for helping
madhusmita sahu on 4 May 2020
thank you so much sir

BAPPA MUKHERJEE on 6 Dec 2019
Hi
How can I replace some values with NAN form a time sries.

carolina franco on 28 Jan 2020
Hi,
Another simple way to understand what's going on .
For me, it works well in R2014a. You only need to enter the matrix with NaN values without specifying the columns where NaN values are.
Here NaN values are replaced by 0s but you can easily modify it in the 8th line of this code:
%Input
m_data=C{1,1}; % Matrix with NaN values
%Code
s1=size(m_data,1);
for i= 1: s1
msubs=m_data(i,1:end); % Save existing data in ith row of m_data
msubs=msubs(isnan(m_data(i,1:end))==0); %Substitute matrix/ taking only non-NaN values
m_data(i,1:end)=0; %Erase all existing values in ith row of m_data and REPLACE by 0s
m_data(i,1:size(msubs,2))=msubs; %Substitute values without NaN
end