필터 지우기
필터 지우기

make some matrices from one matrix without repeating the same numbers

조회 수: 1 (최근 30일)
fatema saba
fatema saba 2015년 11월 4일
편집: Thorsten 2015년 11월 6일
Hi I have matrix A
A=[1:1000]
I randomly made matrix B on the basis of 20 percent of (numel(A)) like that:
B= randi(1000,[1 200])
then I calculate difference between this two matrix and named it sdB.
sdB=setdiff(A,B)
now I want to determine matrix C on the basis of 20 percent of (numel(A) (it means 200 numbers) from matrix sdB. Then calculate difference between matrix B and C (or sdC). this process must be continue until in sum all 1000 numbers are determined. Is it possible to guide me please?

채택된 답변

Thorsten
Thorsten 2015년 11월 4일
Using B= randi(1000,[1 200]) you don't get 200 unique numbers. If your goal is to split the numbers from 1 to 1000 in random order into 5 chunks of 200 numbers, use
R = randperm(1000);
for i = 1:5
A(i,:) = R([1:200]+(i-1)*200);
end
A(i,:) is then your i'th set of 200 numbers randomly picked from 1000, but without repetitions.
  댓글 수: 2
fatema saba
fatema saba 2015년 11월 6일
Thank you Thorsten, however is it possible to vectorise this code and concise it?
Thorsten
Thorsten 2015년 11월 6일
편집: Thorsten 2015년 11월 6일
That's possible:
R = randperm(1000);
A = reshape(R, 200, [])';

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by