How to code to perform the following tasks?

1 回表示 (過去 30 日間)
Assen Beshr
Assen Beshr 2022 年 5 月 19 日
コメント済み: Assen Beshr 2022 年 5 月 22 日
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 件のコメント
KSSV
KSSV 2022 年 5 月 19 日
Question is not clear.
Assen Beshr
Assen Beshr 2022 年 5 月 19 日
編集済み: Assen Beshr 2022 年 5 月 19 日
Given parametrs are n,npop, collum vector with name Location and to form Matrix with name Sizes and its value range depend on 'n' value as stated as well as Matrix with name Locations and its value is random value from collum vector Location
the required tasks is How to generate the matrix Look like as example?
for example n=1
Locations=[116
82
27
4
136];
Sizes= [ 475
72
5421
3310
1015 ];
Positions= [116 475
82 72
27 5421
4 3310
136 1015 ]; i.e row size= npop , column size= 2*n for matrx Positions and its element value for first column is random value of column vector which is give and also second column values are random with range as stated above which depends on value of 'n'.

サインインしてコメントする。

採用された回答

David Hill
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 件のコメント
David Hill
David Hill 2022 年 5 月 20 日
It is an example, the rest is for you to figure out.
Assen Beshr
Assen Beshr 2022 年 5 月 22 日
Thank you very much Davil Hail for your support. with some modification the question was answerd as follows:
n=3;nPop=30;%Location=1:137;
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];
Locations = Location(randi(numel(Location),nPop,n));
s=[9476,4739,3157,2650];
Sizes=reshape(randperm(s(n),n*nPop)-1,nPop,n);
positions=[Locations,Sizes];

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by