필터 지우기
필터 지우기

Generate rand of two specific numbers and not a range

조회 수: 2 (최근 30일)
Sara AR
Sara AR 2019년 10월 30일
댓글: Sara AR 2019년 10월 30일
I have generated a matrix of an image and im trying to generate the rand function to pick between two specific numbers and not a range of numbers. So lets say I want the third row of the third column to be either 1 or 50, randomly picked. how exactly do i make that pixel be equal to random number equation that i made?

채택된 답변

Sai Bhargav Avula
Sai Bhargav Avula 2019년 10월 30일
Hi, One way for this is as below
val = [1,50];
r = randi([1, 2], 1); % Get a 1 or 2 randomly.
Value = val(r) ;
Replace with the random value
Img(3,3)= Value; % the example you mentioned
Hope this helps

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by