|
|
Re: Matrix variable with parametric elements
Posted:
Dec 26, 2012 7:32 AM
|
|
On 12/26/2012 6:26 AM, Nasser M. Abbasi wrote: > On 12/26/2012 5:51 AM, Michael Doukas wrote: >> Hello everybody, >> >> I am fairly new to Matlab so please, if you can, reply as plain as possible. >> >> I want to create a 40X9 matrix and store it as a variable, but the matrix elements must be "parametric", meaning that i want the elements of the: >> first column to take random integer values in the range 0:2 (i.e. integers 0 or 1 or 2), >> second column to take random integer values in the range 3:6 (i.e. 3 or 4 or 5 or 6), >> ... >> ninth column to take random integer values within the range 56:67 (i.e. 56 or 57...67) >> >> Please let me know in case you want me to further explain my problem. >> >> Thanks, >> Mike >> > > How did you get that columns 9 will have 56:67? I think it should be 52:62 >
Ok, please try this. Nothing fancy, just a loop (oh no!)
------------------- nRow = 40; nCol = 9; from = 0; to = 2; A = zeros(nRow,nCol);
for j = 1:nCol A(:,j) = randi([from,to],nRow,1); from = to+1; to = from+j+2; end ----------------
A = 0 5 11 17 20 32 33 48 52 2 6 8 17 20 32 35 47 54 0 5 11 15 21 26 40 43 52 1 5 11 15 21 27 33 51 54 1 6 9 12 20 32 40 47 53 2 3 11 17 20 29 33 46 54 1 4 11 14 21 29 39 51 53 1 3 9 13 22 29 37 48 53 2 3 10 17 24 31 34 46 58 1 5 9 16 23 29 38 50 61 1 5 7 17 20 26 34 47 62 2 6 9 13 23 28 39 47 54 0 5 10 16 18 28 38 48 57 2 3 9 15 18 32 33 45 56 0 6 8 12 18 29 33 44 57 2 6 11 14 19 30 34 47 54 1 4 11 13 20 30 33 50 52 2 5 11 16 20 27 36 46 56 1 6 8 13 18 29 40 43 53 1 5 9 17 21 29 38 46 52 2 6 11 16 18 26 37 45 62 0 4 11 14 19 29 40 46 56 0 4 10 14 22 30 33 50 62 2 5 8 16 24 28 41 46 60 1 4 10 17 24 31 33 45 52 0 5 7 15 21 30 37 45 59 1 5 9 15 24 27 34 43 59 0 5 10 13 21 28 38 44 59 0 4 11 14 21 28 33 42 58 0 3 11 16 20 31 39 46 54 0 4 9 17 21 30 40 44 60 0 4 10 16 21 28 41 44 54 1 6 9 12 18 30 41 46 56 0 6 11 16 24 32 37 43 61 2 5 11 14 18 31 35 46 61 0 3 11 14 21 30 33 49 56 2 3 8 12 23 25 37 44 55 1 5 9 16 20 28 38 49 58 0 4 8 13 22 29 39 42 62 1 6 10 13 23 28 33 45 62
--Nasser
|
|