MATLAB: Sorting NaN

sort

say if i have a matrix a:
a=[1 2 3;4 5 6;7 8 9;NaN NaN NaN]
i want to sort this in descending order, so i use
sort(a,1,'descend')
but the problem is, matlab puts the NaN at the top, is there a way to make it so that NaN is at the bottom? Thanks

Best Answer

As long as you don't have any -Inf values in a, you could always do a quick hack:
a=[1 2 3;4 5 6;7 8 9;NaN NaN NaN]
a(isnan(a)) = -Inf;
a = sort(a,1,'descend');
a(isinf(a)) = NaN