how to divide a number of nodes in four groups randomly
3 views (last 30 days)
Show older comments
sneha sharma
on 2 Nov 2015
Commented: sneha sharma
on 2 Nov 2015
I have many nodes.and to make the program simple I want to divide them in different groups randomly.Please help.
0 Comments
Accepted Answer
Image Analyst
on 2 Nov 2015
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);
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!