how to divide a number of nodes in four groups randomly
조회 수: 3 (최근 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!