Do we have any Fucntion which can generate +1 and -1 randomly????
조회 수: 1 (최근 30일)
이전 댓글 표시
I am using the following thing to generate it...
a=rand(1,10);
b=round(a);
b( b==0 )=-1;
So is there any other best way to genrate +1 and -1 randomly
댓글 수: 0
채택된 답변
Mohammad Abouali
2014년 10월 26일
편집: Mohammad Abouali
2014년 10월 26일
I don't think there is any function doing that.
Here is another approach:
sign(rand(1,10)-0.5)
or
(-1).^(round(rand(1,10)))
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!