how can i specify a parameter for each element of a random matrix?

i know the function a=randi([imin,imax],n,m) but in there imin and imax are parameters of the matrix in general, and i need to specify parameters of each element or each column of the matrix. HELP !!!!

2 commentaires

rand([inmin, imax], n, m) is not valid. There is a randi() that uses that syntax: is that what you want? The code would be different for integers than for continous values because of boundary effects and the way rounding works.
yes i meant randi for integers values :)

Connectez-vous pour commenter.

Réponses (2)

Roger Stafford
Roger Stafford le 10 Avr 2016
Modifié(e) : Roger Stafford le 10 Avr 2016
Let Imin and Imax be n x m matrices in which Imin(i,j) is to be the lower limit for a(i,j) and Imax(i,j) its upper limit.
a = ceil((Imax-Imin+1).*rand(n,m)+Imin-1);
I have assumed that you meant 'randi' in your description, and that you wish to generate integers.
Mr Stafford answer is correct,
yet
my reading of the question is that 'for each column' means Eldha only has 2 1xM vectors defining max and min, not an NxM matrix defining NxM ranges.
For instance let's say you want to generate 21 rows, and have 12 boundaries
% N: rows M: columns, for instance:
N=21
M=12
% v_max=[max1 max2 .. maxM]
% v_min=[min1 min2 .. minM]
% generating boundaries, change v_max v_min to required values
v_max=randi([10 20],1,M);v_min=randi([-20 10],1,M)
A=zeros(N,M)
for k=1:M
A(:,k)=randi([v_min(k) v_max(k)],N,1)
end
If you find this answer of any help solving your question, please click on the thumbs-up vote link,
thanks in advance
John

Catégories

En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by