Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Shifting NaNs to top of matrix
Replies: 6   Last Post: Mar 25, 2013 6:49 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Loren Shure

Posts: 990
Registered: 12/7/04
Re: Shifting NaNs to top of matrix
Posted: Mar 22, 2013 9:56 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


"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




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.