Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
replace missing value to nan

Subject: replace missing value to nan

From: FARSHID

Date: 24 Sep, 2010 11:27:04

Message: 1 of 11

Dear All
I got sea surface high from observation is 3d then converted to my grid point by interp2 function. The missing valu "1.8447e+19" is include both of them.
I try fill missing value with "nan" by wrote for example following code so I couldn't remove missing value. Please guide me what I do.
 nn=size(zeta);
nn(1)=12; nn(2)=212; nn(3)=236;
for i = 1 : nn(1)
    for j = 1 : nn(2)
        for k = 1 : nn(3)
            if zeta(i,j,k)<1.84467440737096e+19;
                ssh(i,j,k)=zeta(i,j,k);
                  else
                ssh(i,j,k)=nan;
            end
       end
end

Best Regards
F.Daryabor

Subject: replace missing value to nan

From: Patrick

Date: 24 Sep, 2010 12:58:04

Message: 2 of 11

One Line...

zeta(zeta>=1.84467440737096e+19)=nan;

Matlab is awesome

"FARSHID " <fdaryabor@gmail.com> wrote in message <i7i1u8$m6o$1@fred.mathworks.com>...
> Dear All
> I got sea surface high from observation is 3d then converted to my grid point by interp2 function. The missing valu "1.8447e+19" is include both of them.
> I try fill missing value with "nan" by wrote for example following code so I couldn't remove missing value. Please guide me what I do.
> nn=size(zeta);
> nn(1)=12; nn(2)=212; nn(3)=236;
> for i = 1 : nn(1)
> for j = 1 : nn(2)
> for k = 1 : nn(3)
> if zeta(i,j,k)<1.84467440737096e+19;
> ssh(i,j,k)=zeta(i,j,k);
> else
> ssh(i,j,k)=nan;
> end
> end
> end
>
> Best Regards
> F.Daryabor

Subject: replace missing value to nan

From: FARSHID

Date: 24 Sep, 2010 17:19:20

Message: 3 of 11

Dear Patrick
It doesn't work I used it before.
Really tested different ways but didn't work none.
Best Regards
 
Sent details of data as following:

nc = netcdf('msla_h.nc', 'noclobber');
if isempty(nc), return, end
 
%% Global attributes:
 
nc.title = ncchar(''SSALTO/DUACS - NRT MSLA - Merged Product'');
nc.institution = ncchar('' '');
nc.references = ncchar('' '');
nc.source = ncchar('' '');
nc.Conventions = ncchar(''CF-1.0'');
nc.history = ncchar(''Data extracted from dataset http://opendap.aviso.oceanobs.com/thredds/dodsC/dataset-duacs-nrt-over30d-global-merged-msla-h'');
nc.time_min = ncdouble(518616);
nc.time_max = ncdouble(527376);
nc.julian_day_unit = ncchar(''hours since 1950-01-01'');
nc.latitude_min = ncdouble(-20.0050076288087);
nc.latitude_max = ncdouble(30.0889553945206);
nc.longitude_min = ncdouble(89.999999999991);
nc.longitude_max = ncdouble(129.999999999987);
 
%% Dimensions:
 
nc('time') = 366;
nc('NbLatitudes') = 157;
nc('NbLongitudes') = 121;
 
%% Variables and attributes:
 
nc{'time'} = nclong('time'); %% 366 elements.
nc{'time'}.units = ncchar(''hours since 1950-01-01'');
nc{'time'}.CoordinateAxisType_ = ncchar(''Time'');
nc{'time'}.valid_min = nclong(518616);
nc{'time'}.valid_max = nclong(527376);
nc{'time'}.axis = ncchar(''T'');
nc{'time'}.long_name = ncchar(''time'');
nc{'time'}.standard_name = ncchar(''time'');
 
nc{'NbLatitudes'} = ncdouble('NbLatitudes'); %% 157 elements.
nc{'NbLatitudes'}.FillValue_ = ncdouble(1.84467440737096e+019);
nc{'NbLatitudes'}.long_name = ncchar(''Latitudes'');
nc{'NbLatitudes'}.units = ncchar(''degrees_north'');
nc{'NbLatitudes'}.CoordinateAxisType_ = ncchar(''Lat'');
nc{'NbLatitudes'}.valid_min = ncdouble(-20.0050076288087);
nc{'NbLatitudes'}.valid_max = ncdouble(30.0889553945206);
nc{'NbLatitudes'}.axis = ncchar(''Y'');
nc{'NbLatitudes'}.standard_name = ncchar(''latitude'');
 
nc{'NbLongitudes'} = ncdouble('NbLongitudes'); %% 121 elements.
nc{'NbLongitudes'}.FillValue_ = ncdouble(1.84467440737096e+019);
nc{'NbLongitudes'}.long_name = ncchar(''Longitudes'');
nc{'NbLongitudes'}.units = ncchar(''degrees_east'');
nc{'NbLongitudes'}.CoordinateAxisType_ = ncchar(''Lon'');
nc{'NbLongitudes'}.valid_min = ncdouble(89.999999999991);
nc{'NbLongitudes'}.valid_max = ncdouble(129.999999999987);
nc{'NbLongitudes'}.axis = ncchar(''X'');
nc{'NbLongitudes'}.standard_name = ncchar(''longitude'');
 
nc{'Grid_0001'} = ncfloat('time', 'NbLongitudes', 'NbLatitudes'); %% 6952902 elements.
nc{'Grid_0001'}.CoordinateAxes_ = ncchar(''time NbLongitudes NbLatitudes '');
nc{'Grid_0001'}.FillValue_ = ncfloat(1.84467440737096e+019);
nc{'Grid_0001'}.long_name = ncchar(''H'');
nc{'Grid_0001'}.units = ncchar(''cm'');
 
endef(nc)
close(nc)
 
"Patrick " <phooker@dgigeoscience.com> wrote in message <i7i78s$bt7$1@fred.mathworks.com>...
> One Line...
>
> zeta(zeta>=1.84467440737096e+19)=nan;
>
> Matlab is awesome
>
> "FARSHID " <fdaryabor@gmail.com> wrote in message <i7i1u8$m6o$1@fred.mathworks.com>...
> > Dear All
> > I got sea surface high from observation is 3d then converted to my grid point by interp2 function. The missing valu "1.8447e+19" is include both of them.
> > I try fill missing value with "nan" by wrote for example following code so I couldn't remove missing value. Please guide me what I do.
> > nn=size(zeta);
> > nn(1)=12; nn(2)=212; nn(3)=236;
> > for i = 1 : nn(1)
> > for j = 1 : nn(2)
> > for k = 1 : nn(3)
> > if zeta(i,j,k)<1.84467440737096e+19;
> > ssh(i,j,k)=zeta(i,j,k);
> > else
> > ssh(i,j,k)=nan;
> > end
> > end
> > end
> >
> > Best Regards
> > F.Daryabor

Subject: replace missing value to nan

From: Sean

Date: 24 Sep, 2010 17:34:09

Message: 4 of 11

"FARSHID " <fdaryabor@gmail.com> wrote in message <i7imio$9c4$1@fred.mathworks.com>...
> Dear Patrick
> It doesn't work I used it before.
> Really tested different ways but didn't work none.
> Best Regards

> > One Line...
> >
> > zeta(zeta>=1.84467440737096e+19)=nan;
> >
> > Matlab is awesome
> >

%Try:
SSH = zeta;
SSH(zeta>=1.84467440737096e+19) = nan;

Subject: replace missing value to nan

From: FARSHID

Date: 25 Sep, 2010 05:35:06

Message: 5 of 11

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i7ineh$69j$1@fred.mathworks.com>...
> "FARSHID " <fdaryabor@gmail.com> wrote in message <i7imio$9c4$1@fred.mathworks.com>...
> > Dear Patrick
> > It doesn't work I used it before.
> > Really tested different ways but didn't work none.
> > Best Regards
>
> > > One Line...
> > >
> > > zeta(zeta>=1.84467440737096e+19)=nan;
> > >
> > > Matlab is awesome
> > >
>
> %Try:
> SSH = zeta;
> SSH(zeta>=1.84467440737096e+19) = nan;
Dear Patrick
Still it doesn't work.
Do you remember any way because tried different way.
Best Regards
F.Daryabor
  

Subject: replace missing value to nan

From: Ross W

Date: 25 Sep, 2010 06:04:22

Message: 6 of 11

"FARSHID " <fdaryabor@gmail.com> wrote in message <i7k1ma$cq$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i7ineh$69j$1@fred.mathworks.com>...
> > "FARSHID " <fdaryabor@gmail.com> wrote in message <i7imio$9c4$1@fred.mathworks.com>...
> > > Dear Patrick
> > > It doesn't work I used it before.
> > > Really tested different ways but didn't work none.
> > > Best Regards
> >
> > > > One Line...
> > > >
> > > > zeta(zeta>=1.84467440737096e+19)=nan;
> > > >
> > > > Matlab is awesome
> > > >
> >
> > %Try:
> > SSH = zeta;
> > SSH(zeta>=1.84467440737096e+19) = nan;
> Dear Patrick
> Still it doesn't work.
> Do you remember any way because tried different way.
> Best Regards
> F.Daryabor
>

Can you tell us what you mean when you say "it doesn't work".

Is there an error message?
Does it execute and some large values get changed to NaN but not all of them?

I wonder if the problem is to do with limited precision. How about this?

SSH = zeta;
SSH(zeta>=1.844e+19) = nan;

Ross

Subject: replace missing value to nan

From: FARSHID

Date: 25 Sep, 2010 15:00:14

Message: 7 of 11

"Ross W" <rosswoodskiwi@hotmail.com> wrote in message <i7k3d6$h0k$1@fred.mathworks.com>...
> "FARSHID " <fdaryabor@gmail.com> wrote in message <i7k1ma$cq$1@fred.mathworks.com>...
> > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i7ineh$69j$1@fred.mathworks.com>...
> > > "FARSHID " <fdaryabor@gmail.com> wrote in message <i7imio$9c4$1@fred.mathworks.com>...
> > > > Dear Patrick
> > > > It doesn't work I used it before.
> > > > Really tested different ways but didn't work none.
> > > > Best Regards
> > >
> > > > > One Line...
> > > > >
> > > > > zeta(zeta>=1.84467440737096e+19)=nan;
> > > > >
> > > > > Matlab is awesome
> > > > >
> > >
> > > %Try:
> > > SSH = zeta;
> > > SSH(zeta>=1.84467440737096e+19) = nan;
> > Dear Patrick
> > Still it doesn't work.
> > Do you remember any way because tried different way.
> > Best Regards
> > F.Daryabor
> >
>
> Can you tell us what you mean when you say "it doesn't work".
>
> Is there an error message?
> Does it execute and some large values get changed to NaN but not all of them?
>
> I wonder if the problem is to do with limited precision. How about this?
>
> SSH = zeta;
> SSH(zeta>=1.844e+19) = nan;
>
> Ross

Dear Ross
Yes it execute but the large values doesn't change to NaN.
Best Regards
F.Daryabor

Subject: replace missing value to nan

From: Ross W

Date: 26 Sep, 2010 00:52:04

Message: 8 of 11

"FARSHID " <fdaryabor@gmail.com> wrote in message <i7l2pu$o6o$1@fred.mathworks.com>...
> "Ross W" <rosswoodskiwi@hotmail.com> wrote in message <i7k3d6$h0k$1@fred.mathworks.com>...
> > "FARSHID " <fdaryabor@gmail.com> wrote in message <i7k1ma$cq$1@fred.mathworks.com>...
> > > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i7ineh$69j$1@fred.mathworks.com>...
> > > > "FARSHID " <fdaryabor@gmail.com> wrote in message <i7imio$9c4$1@fred.mathworks.com>...
> > > > > Dear Patrick
> > > > > It doesn't work I used it before.
> > > > > Really tested different ways but didn't work none.
> > > > > Best Regards
> > > >
> > > > > > One Line...
> > > > > >
> > > > > > zeta(zeta>=1.84467440737096e+19)=nan;
> > > > > >
> > > > > > Matlab is awesome
> > > > > >
> > > >
> > > > %Try:
> > > > SSH = zeta;
> > > > SSH(zeta>=1.84467440737096e+19) = nan;
> > > Dear Patrick
> > > Still it doesn't work.
> > > Do you remember any way because tried different way.
> > > Best Regards
> > > F.Daryabor
> > >
> >
> > Can you tell us what you mean when you say "it doesn't work".
> >
> > Is there an error message?
> > Does it execute and some large values get changed to NaN but not all of them?
> >
> > I wonder if the problem is to do with limited precision. How about this?
> >
> > SSH = zeta;
> > SSH(zeta>=1.844e+19) = nan;
> >
> > Ross
>
> Dear Ross
> Yes it execute but the large values doesn't change to NaN.
> Best Regards
> F.Daryabor

So then maybe the problem is that the code is testing for equality on a floating point number.

Does this coded help?
SSH = zeta;
SSH(zeta>=1.844e+19) = nan;

Ross

Subject: replace missing value to nan

From: Matt Fig

Date: 26 Sep, 2010 01:05:03

Message: 9 of 11

"Ross W" <rosswoodskiwi@hotmail.com> wrote in message
> So then maybe the problem is that the code is testing for equality on a floating point number.
>
> Does this coded help?
> SSH = zeta;
> SSH(zeta>=1.844e+19) = nan;
>
> Ross


Try Ross's code, and before you write back, run this and TELL WHAT IS RETURNED:

class(SSH)
max(SSH(:))

Subject: replace missing value to nan

From: FARSHID

Date: 26 Sep, 2010 15:34:04

Message: 10 of 11

"Matt Fig" <spamanon@yahoo.com> wrote in message <i7m67v$rj3$1@fred.mathworks.com>...
> "Ross W" <rosswoodskiwi@hotmail.com> wrote in message
> > So then maybe the problem is that the code is testing for equality on a floating point number.
> >
> > Does this coded help?
> > SSH = zeta;
> > SSH(zeta>=1.844e+19) = nan;
> >
> > Ross
>
>
> Try Ross's code, and before you write back, run this and TELL WHAT IS RETURNED:
>
> class(SSH)
> max(SSH(:))
Dear Ross
class and max val as following:
>> class(SSH)

ans =

double

>> max(SSH(:))

ans =

  1.8447e+019
Best Regards
F.Daryabo

Subject: replace missing value to nan

From: Steven_Lord

Date: 27 Sep, 2010 03:20:25

Message: 11 of 11



"FARSHID " <fdaryabor@gmail.com> wrote in message
news:i7k1ma$cq$1@fred.mathworks.com...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message
> <i7ineh$69j$1@fred.mathworks.com>...
>> "FARSHID " <fdaryabor@gmail.com> wrote in message
>> <i7imio$9c4$1@fred.mathworks.com>...
>> > Dear Patrick
>> > It doesn't work I used it before.
>> > Really tested different ways but didn't work none.
>> > Best Regards
>>
>> > > One Line...
>> > >
>> > > zeta(zeta>=1.84467440737096e+19)=nan;
>> > >
>> > > Matlab is awesome
>> > >
>>
>> %Try:
>> SSH = zeta;
>> SSH(zeta>=1.84467440737096e+19) = nan;
> Dear Patrick Still it doesn't work.
> Do you remember any way because tried different way.

Lower your threshold. The elements of zeta may _be displayed_ as that exact
number but the actual value may be smaller.

If there's a big gap between the largest "correct value" and the smallest
"missing value" choose something in the middle of that gap, rather than
choosing what you think is the exact smallest "missing value".

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us