how to divide a number of nodes in four groups randomly
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
sneha sharma
il 2 Nov 2015
Commentato: sneha sharma
il 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 Commenti
Risposta accettata
Image Analyst
il 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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!