How to code to perform the following tasks?
조회 수: 1 (최근 30일)
이전 댓글 표시
n=1,2,3,4 or input('Enter the Number [1-4]')
npop=5;
Location=[2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
30
31
44
45
46
48
49
77
79
80
82
86
87
88
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137];
how to code to get 'Locations'= 'n' random 'Location' of column and npop rows
And also,
'Sizes' =random value for n=1, is 0-9475, n=2 is 0-4738,n=3 is 0-3156,n=4 is 0-2649 with npop rows
finaly, positions=[Locations, Sizes];
for example: n=2; Locations=[48 127
7 18
21 10
48 130
137 3];
Sizes= [678 107
78 138
2890 100
48 13
867 93];
then Finaly
Positions=[48 127 678 107
7 18 78 138
21 10 2890 100
48 130 48 13
137 3 867 93];
댓글 수: 2
채택된 답변
David Hill
2022년 5월 19일
n=2;npop=5;Location=1:137;
Locations=reshape(Location(randperm(length(Location),n*npop)),npop,n);
s=[9476,4739,3157,2650];
Sizes=reshape(randperm(s(n),n*npop)-1,npop,n);
positions=[Locations,Sizes];
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!