필터 지우기
필터 지우기

Used CROSSVALIND to Randomize rows with numerical only but not NAN

조회 수: 2 (최근 30일)
balandong
balandong 2017년 8월 7일
댓글: balandong 2017년 8월 8일
Dear all, I have a column double vector which consist 0,1 and NAN. The big idea was to assign the column vector into either one of the group, group 1, group 2,... group 10. The group assignment was realized using CROSSVALIND. However, I only want to assign iff the element is 0 or 1.
For example.
Assume the column double vector
xx = [NaN;NaN;NaN;1;1;;0;0;1;NaN]
Thus, the expected output using CRASSVALIND will be something will
group = [NAN;NAN;NAN;3;4;1;7;4;NAN]
Simply plug in the xx vector as following
Group = crossvalind('Kfold',xx,10);
produce the following error
Error using accumarray
First input SUBS must contain positive integer subscripts.
Thus, the following dirty work is propose
load('xx');
yyy =find (~isnan(xx));
Group = crossvalind('Kfold',yyy ,10);
newGroup =nan (length(xx),1);
for i=1:length(yyy)
newGroup(yyy(i))= Group(i);
end
However, I wanted to know if MATLAB allow better ways to achieve the same goal?
I attached together the MAT file containing the xx vector together with this thread Thanks in advance for the time entertaining this thread.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 8월 7일
Not a "better" way, but correcting your code and optimizing slightly:
load('xx');
mask = ~isnan(xx);
Group = crossvalind('Kfold', xx(mask), 10);
newGroup = nan(length(xx),1);
newGroup(mask) = Group;

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by