필터 지우기
필터 지우기

Randi except one variable

조회 수: 23 (최근 30일)
Alice Amitrano
Alice Amitrano 2019년 3월 18일
댓글: Walter Roberson 2021년 6월 18일
My randi matrix can have random values except one value, how do I generate it?
  댓글 수: 1
Kevin Phung
Kevin Phung 2019년 3월 18일
which value? are you talking about a particular index? and what would that value be?

댓글을 달려면 로그인하십시오.

답변 (2개)

Kevin Phung
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.

Walter Roberson
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
Akana Juliet 2021년 6월 18일
@Walter Roberson Hi! for "values_to_exclude" how do you include multiple integers?
Walter Roberson
Walter Roberson 2021년 6월 18일
values_to_exclude = [3, 8, -5:-2]
just create a list.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by