i wan to generate the random number between two number with condition
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sun Heat
le 21 Juin 2020
Modifié(e) : Rik
le 21 Juin 2020
i have this kind of code:-
mini=[2 0.2]; maxi=[20 10]; x=zeros(50,2);
for i= 1:var
x(:,i)=mini(i)+(maxi(i)-mini(i))*rand(50,1);
end
i want to generate the number which is 40% less than the number in the 1st coloum for example.
2-0.8,3-1.2,4-1.6,5-2,6-2.4,10-4,11-4.4,15-6,20-7.
0 commentaires
Réponse acceptée
Thiago Henrique Gomes Lobato
le 21 Juin 2020
Modifié(e) : Thiago Henrique Gomes Lobato
le 21 Juin 2020
If your second column has values equal to 40% of the first, then they are not random. You can vectorize this in the following form:
VectorSize = 5;
mini=[2]; maxi=[20 ]; x=zeros(VectorSize,1);
x=mini+(maxi-mini)*rand(VectorSize,1);
% Generate extra columns
NofExtraCollums = 1;
x = x.*(0.4.^([0:NofExtraCollums]))
x(:,2)./x(:,1)
x =
18.4878 7.3951
2.0207 0.8083
10.3241 4.1296
9.6383 3.8553
10.2965 4.1186
ans =
0.4000
0.4000
0.4000
0.4000
0.4000
Plus de réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!