How to assign two values randomly among 2 variables?
이전 댓글 표시
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
KSSV
2016년 10월 6일
sensor1 = (b1-a1).*rand(100,1) + a1;
sensor2 = (b2-a2).*rand(100,1) + a2;
wont it work? As the values are random, define sensor values itself random.
Bhavya Gandham
2016년 10월 6일
Bhavya Gandham
2016년 10월 7일
답변 (2개)
r=rand; %random number between 0 and 1
if r<0.5
sensor1 = c1;
sensor2 = c2;
else
sensor1 = c2;
sensor2 = c1;
end
Thorsten
2016년 10월 6일
idx = rand(100,1);
sensor1 = c1;
sensor1(idx>0.5) = c2;
sensor2 = c1;
sensor2(idx<=0.5) = c2;
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!