Filter löschen
Filter löschen

Generate rand of two specific numbers and not a range

2 Ansichten (letzte 30 Tage)
Sara AR
Sara AR am 30 Okt. 2019
Kommentiert: Sara AR am 30 Okt. 2019
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?

Akzeptierte Antwort

Sai Bhargav Avula
Sai Bhargav Avula am 30 Okt. 2019
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

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by