Generate Array of Random Values
显示 更早的评论
I am trying to write a function to generate an array of random values as follows:
I have as inputs an array Dims (X by 2) and the number of samples per row Iter.
I need to create an X by Iter array where each row n in the array has uniformly distributed random values between Dims(n,1) and Dims(n,2).
I am trying to do this in an efficient way.
So far I have
Values = rand(size(Dims, 1), Iter);
for i = 1:size(Values, 1)
for j = 1:Iter
Values(i,j) = Values(i,j) * ((Dims(i,2) - Dims(i,1)) + Dims(i,1);
end
end
Is there a better way to do this?
回答(2 个)
Dims = [5 10; 10 20; 30 100];
Iter = 6;
Values = rand(size(Dims,1),Iter).*(Dims(:,2)-Dims(:,1))+Dims(:,1)
D = sort(randi([-9,9],7,2),2)
V = rand(7,13);
V = V.*diff(D,1,2)+D(:,1)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!