isnan in Dataset Array

2 次查看(过去 30 天)
ARS
ARS 2012-7-25
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.

采纳的回答

Peter Perkins
Peter Perkins 2012-7-26
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by