How to assign two values randomly among 2 variables?

2 Ansichten (letzte 30 Tage)
Bhavya Gandham
Bhavya Gandham am 6 Okt. 2016
Kommentiert: Bhavya Gandham am 7 Okt. 2016
c1 = (b1-a1).*rand(100,1) + a1; c2 = (b2-a2).*rand(100,1) + a2; I have to assign the c1 and c2 values randomly among two variables sensor1 and sensor2. How can I do this? Thanks in advance...
  3 Kommentare
Bhavya Gandham
Bhavya Gandham am 6 Okt. 2016
the ranges of c1 and c2 are different. c1 range is (0,0.7) and c2 range is 90.7,1.2) I have to assign these random values to sensor1 and sensor2 randomly. thanks in advance...

Melden Sie sich an, um zu kommentieren.

Antworten (2)

elias GR
elias GR am 6 Okt. 2016
Bearbeitet: elias GR am 6 Okt. 2016
r=rand; %random number between 0 and 1
if r<0.5
sensor1 = c1;
sensor2 = c2;
else
sensor1 = c2;
sensor2 = c1;
end

Thorsten
Thorsten am 6 Okt. 2016
idx = rand(100,1);
sensor1 = c1;
sensor1(idx>0.5) = c2;
sensor2 = c1;
sensor2(idx<=0.5) = c2;

Kategorien

Mehr zu Creating and Concatenating Matrices 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