フィルターのクリア

Generation of random number which needs to be passed to an array

1 回表示 (過去 30 日間)
Ganesh Kini
Ganesh Kini 2020 年 6 月 15 日
回答済み: Rik 2020 年 6 月 15 日
I have 2 variables named A and B
A has the range from -0.2 to 2.2
B has the range from -3.2 to 0.2
I need all the possible to combinations of A and B in 0.1 steps
for example
FROM
0.1 0.2
-0.1 -0.3 and so on
How do I randomly generate this?
  2 件のコメント
James Tursa
James Tursa 2020 年 6 月 15 日
By randomly, do you mean you want to randomly pick one pair from all possible pairs? Or do you mean you want to generate the set of all possible pairs but then randomly mix them up?
Ganesh Kini
Ganesh Kini 2020 年 6 月 15 日
編集済み: Ganesh Kini 2020 年 6 月 15 日
Thank you for your reply
I want all the sets of randomly mixed values and then I need to iterate them
So, there are two questions
1) How do I randomly pick one set of A and B and then pass it on the array?
2) How do I iterate all the sets of values without using for loop?

サインインしてコメントする。

回答 (1 件)

Rik
Rik 2020 年 6 月 15 日
You can generate all combinations and mix them up like this:
[A,B]=ndgrid(-0.2:0.1:2.2,-3.2:0.1:0.2);
new_order=randperm(numel(A));
A=A(new_order);
B=B(new_order);
Now you can feed it to your next function. Whether you are able to avoid for-loops depends on what function you are trying to call. (and it may not be the optimal strategy to do so at any cost)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by