isnan in Dataset Array

3 visualizzazioni (ultimi 30 giorni)
ARS
ARS il 25 Lug 2012
Hi All, I am sorting a dataset array "RR2" with the below given code and it works perfect. But it positions the rows with NaNs at the top. How can I get rid of the rows with NaNs?
for k=1:738,
sorted=sortrows(rr2,k,'descend');
sorted1(:,k)=sorted(:,1);
end
when I replace the second line with this: sorted=sortrows(~isnan(rr2),k,'descend'); the below given error comes up.
Undefined function 'isnan' for input arguments of type 'dataset'.
Does dataset array not support isnan? any easy way to do this?
Regards,
AMD.

Risposta accettata

Peter Perkins
Peter Perkins il 26 Lug 2012
AMD, you don't say what's in your array, so I'll have to guess that because you're looking for NaNs, all of the variables are double. But a dataset array is still a container, and so functions that you can apply to a double variable won't work on a dataset array, even if all of its variables are double. It is more general, and has to account for the fact that you could have mixed data types in it.
A couple things:
  • That loop seems unnecessary, since sortrows is happy to sort on multiple variables in the dataset:
sorted = sortrows(rr2,1:738,'descend');
Perhaps you are trying to get all the rows with a NaN at the top. I don't think your loop does that though.
  • To find rows with NaN, you can do this:
rowsWithNaN = any(isnan(double(rr2)),2); rr2 = rr2(~rowsWithNaN,:);
If you have access to the R2012b pre-release, you might look there for a slightly simpler way to do that.

Più risposte (0)

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by