Randomly generated row matrix B with constraints?
1 visualizzazione (ultimi 30 giorni)
Matrix A which is generated based on a calculation A=[2 1 1 2]
Matrix B (B is equal to the size of A) needs to be randomly generated so that each of its entries (1,i) are no larger than the respective entries in Matrix A (1,i).
I also need a 0 to be a possible randomly generated number in Matrix B
Any help, much appreciated. I can not figure a way for randi to apply this constraint to the individual columns.
I don't understand what you mean in the sentence "I also need a 0 to be a possible randomly generated number in Matrix B". For the other part try this:
B = A.*rand(size(A));
For each element in A, the corresponding element in B will lie somewhere between 0 and the A element value.
If you expect the elements of B to be integers, that is quite another matter.
Greig il 25 Feb 2015
I guess this is what you are looking for?
for ii = 1:length(A)
B(ii) = randi([0, A(ii)], 1);
It is not so clear exactly what you are after, could you clarify a bit more please.