assign data satisfied rules given
조회 수: 1 (최근 30일)
이전 댓글 표시
i want to insert data randomly and it data must satisfied the rules given. for example, i want to insert 3 type of data (33,22,11) randomly in 22x7 and it must satisfied the rules. let assume i already have data that contain 33,22,11(data) randomly in 22x7 and saved in mat files.how to create a function that satisfied the rules to update that data
(there have 7 column and 22 row)
for every column there should satisfied,
Rules 1
11>=60% of 22
22<=20% of 22
33<=20% of 22
Rules 2
for every row,there must have only one data of 44.
댓글 수: 1
Jan
2011년 5월 11일
The question is unclear. What does "insert 3 type of data (33,22,11) randomly in 22x7" mean? "11 >= 60% of 22"?! 11 is greater than 60% of 22 (==13.2), but 22 is never smaller equal 20% of 22.
At first you state, that you want to insert 3 types of data, but in the last line a 4th value (or type?) appears suddenly.
Please edit your question and clarify your problem with more details.
채택된 답변
Andrei Bobrov
2011년 5월 11일
variant for rules 1
szAA = [22 7];
n2233 = randi(floor(szAA(1)*.2),2,szAA(2));
N = [22-sum(n2233);n2233];
B = cell2mat(arrayfun(@(x)cat(3,randperm(22)',[11*ones(N(1,x),1);22*ones(N(2,x),1);33*ones(N(3,x),1)]),1:size(N,2),'un',0));
AA = B(sub2ind(szAA,B(:,:,1),cumsum(ones(szAA),2))+prod(szAA));
rules 2, so?
AA(sub2ind(szAA,1:szAA(1),randi(szAA(2),1,szAA(1))))=44;
댓글 수: 2
Jan
2011년 5월 11일
@Andrei: You are bold. I was too shy to guess what the question would mean exactly.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!