how to divide a number of nodes in four groups randomly

조회 수: 3 (최근 30일)
sneha sharma
sneha sharma 2015년 11월 2일
댓글: sneha sharma 2015년 11월 2일
I have many nodes.and to make the program simple I want to divide them in different groups randomly.Please help.

채택된 답변

Image Analyst
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by