Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.
|
|
|
Re: Shifting NaNs to top of matrix
Posted:
Mar 22, 2013 10:14 AM
|
|
Thanks. Unfortunately I need the rest of the data to be in the same order.
L.
"Loren Shure" <Loren.Shure@mathworks.com> wrote in message news:kihnul$agh$1@newscl01ah.mathworks.com... > > "ladidalimey" <ladidalimey@gmail.com> wrote in message > news:dwE2t.91776$ZZ.35711@fx06.fr7... >> Hi, >> >> I'm trying to do the following: >> >> Take this example matrix: >> >> test = [nan 1 nan 1 >> 1 1 1 1 >> nan 1 1 nan] >> >> I want to shift all the nans to the top of each column so there is only >> numerical data below, resulting in: >> >> [nan 1 nan nan >> nan 1 1 1 >> 1 1 1 1] >> >> Any ideas for a way of doing this without resorting to a loop? >> >> Thanks. >> >> L. >> >> >> > > You can use sort with the 'descend' option if you don't care how the > non-NaN values are sorted. > > > -- > --Loren > > http://blogs.mathworks.com/loren
|
|
|
|