Used CROSSVALIND to Randomize rows with numerical only but not NAN
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Walter Roberson
am 7 Aug. 2017
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;
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!