Randi except one variable
16 ビュー (過去 30 日間)
古いコメントを表示
My randi matrix can have random values except one value, how do I generate it?
1 件のコメント
Kevin Phung
2019 年 3 月 18 日
which value? are you talking about a particular index? and what would that value be?
回答 (2 件)
Kevin Phung
2019 年 3 月 18 日
I would suggest generating a mxn randi matrix, and just changing the one index to whatever value you wanted it to be.
0 件のコメント
Walter Roberson
2019 年 3 月 18 日
Guessing that you mean that you want to randi() over a range of integer values but that there is a particular value that should never be generated, then:
valid_vals = setdiff(low_value:high_value, values_to_exclude);
result = valid_vals( randi(length(valid_vals), number_of_rows, number_of_columns) );
2 件のコメント
Akana Juliet
2021 年 6 月 18 日
Walter Roberson
2021 年 6 月 18 日
values_to_exclude = [3, 8, -5:-2]
just create a list.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!