File Exchange

image thumbnail

pushNaNs

version 1.0 (1.93 KB) by

Pushes NaNs to the bottom of each column of X.

1 Download

Updated

View License

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.

Comments and Ratings (3)

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.

Daniel

Daniel (view profile)

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.

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!

MATLAB Release
MATLAB 8.0 (R2012b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video