Be the first to rate this file! 9 Downloads (last 30 days) File Size: 1.93 KB File ID: #41559

pushNaNs

by

 

Pushes NaNs to the bottom of each column of X.

| Watch this File

File Information
Description

X = pushnans(X,truncate)

Pushes nans to the bottom of each column of X. It should be pretty fast.

The second input is an optional flag. If true, the whole-nan rows at the bottom of X are removed.

Two slightly different algorithms are implemented in the function together with a simple check to select the faster version: which is faster depends on what fraction of the input matrix is non-NaN.

Note that only limited testing has been done - please report problems below. I would also be interested to hear if there are more efficient ways of implementing this.

MATLAB release MATLAB 8.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
02 May 2013 Vanessa

thanks :) I'm definitely not disappointed... just curious! I agree that sometimes it is fulfilling to code up something spontaneously without having a solid application for it, but knowing that it might be useful in the future.

01 May 2013 Daniel

Vanessa,
Sorry to disappoint, but I think you're probably more or less right. The situation in which I thought the function would be useful turned out to be entirely avoidable, after much TLC to the script in question (wading through someone else's lazy coding).
Actually I wrote the function after I'd already realised it wasn't needed, I was just curious to see how it could be done neatly and reckoned there may occasionally be a need for it.

01 May 2013 Vanessa

I'm curious what this script would be used for? it's usually pretty easy to index the NaNs and then manipulate them that way, and given that indices usually have meaning, I'm wondering why I'd want to push the NaNs to the bottom and corrupt the ordering. Thanks!

Contact us