Used CROSSVALIND to Randomize rows with numerical only but not NAN
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (1 件)
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 Center および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!