フィルターのクリア

How to shuffle numbers for each iteration?

1 回表示 (過去 30 日間)
ASHA PON
ASHA PON 2023 年 1 月 12 日
コメント済み: Dyuman Joshi 2023 年 1 月 19 日
I am having 'n' randomnly generated positive decimal number. With this input I have performed some set of mathematical calculations. Now i need to repeat the mathematical calculations with changed order of decimal number and this has to be followed for each iteration until a certain condition is met.
Example:
A= 5, 2, 4, 3, 7, 1, 6
Expected output: Shuffle decimal number for each iteration. [only positive number is required]
  7 件のコメント
ASHA PON
ASHA PON 2023 年 1 月 19 日
Hello Dyuman joshi. The code you have suggested works very well, when it is applied seperately. But while i use this same code and apply some calculation after randperm(n), I didn't get different decimal numbers for each iteration. Can you please guide me where I am making mistake. Thank you.
Dyuman Joshi
Dyuman Joshi 2023 年 1 月 19 日
Can you show your code? Without the code, it is difficult to tell where the problem is.

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

回答 (1 件)

Tobias
Tobias 2023 年 1 月 12 日
It seems you try to do something like a minmum search. Probably, you can solve the origin problem in a more target oriented way.
For your question to shuffle a vector you could do something like this:
Expect having a vector with several digits. In this example 1 to 7:
vector = 1:7;
For example, you could shuffle it like this:
vector = vector(randperm(length(vector)));

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by