mockup = [3,5,nan,2,4,nan,10,nan];
How can I sort this vector in a descending order while ignoring the NaNs? The resulting vector must have the same length as mockup, i.e. I need to put all NaNs at the end. The result should like like this:
mockupSorted = [10,5,4,3,2,NaN,NaN,NaN]
Actually, I am interested in the respective indices, i.e. the second output vector of the sort function. So, I am looking for
mockupSortedIdx = [7,2,5,1,4,NaN,NaN,NaN]
You can use the two outputs of
sortand then useisnanto modify the ordering of the two outputs.The other option is to use
ascendsort and just sort the negative ofmockupsince theascendsort will place theNaNvalues at the end.