selcting 3 values from top 10 values

조회 수: 1 (최근 30일)
Pat
Pat 2011년 9월 14일
I am working on data mining,I have 1000*1rows and columns ,I want to select 3 values from 100 vales and next 3 from 2ng 100 and next 3 fro 3rd 100,finally i need 30 values (3 from each hundred),can any one tell how to process
  댓글 수: 2
Jan
Jan 2011년 9월 14일
Should the elements be chosen randomly? Are repetitions allowed?
the cyclist
the cyclist 2011년 9월 14일
Pat, be aware that Nirmal's solution below assume you want the first three values of each set of 100, and Jan's assumes a random three. You might want to be more specific.

댓글을 달려면 로그인하십시오.

답변 (3개)

Jan
Jan 2011년 9월 14일
Without repetitions:
X = rand(1, 1000);
R = zeros(10, 3);
for i = 1:10
P = randperm(100);
R(i, :) = X(P(1:3) + (i-1)*100);
end
With repetions:
Index = bsxfun(@plus, floor(rand(3, 10)*100), 1:100:1000);
R = x(Index);

Nirmal Gunaseelan
Nirmal Gunaseelan 2011년 9월 14일
A good place to start is Matrix Indexing. One way of achieving this:
result = [];
original = [1:1000];
for itr = 0:100:900
result = [result original(itr + [1,2,3])];
end

Andrei Bobrov
Andrei Bobrov 2011년 9월 14일
My variant
X = randi(500,1000,1);
[~,IR] = sort(rand(100,10));
R = X(bsxfun(@plus,IR(1:3,:),0:size(IR,2)-1));

카테고리

Help CenterFile Exchange에서 Creating Custom Components and Libraries에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by