%File Name: "nans.m"
%Title: Get rid of NaNs
%Author: Shashank G. Sawant
%Notes: Quite honestly I found this somewhere on the internet.
%Here I have just adapted it to a 2D Matrix according to my req.
mwnans=[1 4 NaN 5; 5 4 98 NaN; NaN NaN 3 2]; %Matrix with NaNs
t=find(isnan(mwnans));
mwonans=mwnans; %Initialize Matrix without %NaNs
mwonans(t)=zeros(size(t));
%somehow the mwonans doesn't have the NaNs which mwnans has
Result:
>> nans
>> mwnans
mwnans =
1 4 NaN 5
5 4 98 NaN
NaN NaN 3 2
>> mwonans
mwonans =
1 4 0 5
5 4 98 0
0 0 3 2
>>
Good Riddance!
This entry was posted
on Thursday, November 5, 2009
at 12:50 AM
and is filed under
My Programming Practice
. You can follow any responses to this entry through the
comments feed
.