how to divide a number of nodes in four groups randomly
2 次查看(过去 30 天)
显示 更早的评论
I have many nodes.and to make the program simple I want to divide them in different groups randomly.Please help.
0 个评论
采纳的回答
Image Analyst
2015-11-2
Perhaps this:
% Define parameters:
numPoints = 100; % or length(myNodes) or whatever...
pointsPerSet = round(numPoints/4); % Divide into 4 sets.
% Get a random ordering of all the nodes.
scrambledOrder = randperm(100);
% Get the indexes for the 4 sets
indexesOfSet1 = scrambledOrder(1:pointsPerSet);
indexesOfSet2 = scrambledOrder(pointsPerSet+1:2*pointsPerSet);
indexesOfSet3 = scrambledOrder(2*pointsPerSet+1:3*pointsPerSet);
indexesOfSet4 = scrambledOrder(3*pointsPerSet:end);
% Get the node values for each set.
valuesSet1 = myNodes(indexesOfSet1);
valuesSet2 = myNodes(indexesOfSet2);
valuesSet3 = myNodes(indexesOfSet3);
valuesSet4 = myNodes(indexesOfSet4);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!