Random multiply by negative one

조회 수: 4 (최근 30일)
Alma Bezares
Alma Bezares 2016년 2월 22일
댓글: jgg 2016년 2월 22일
Hello, I bootstrapped a 1000 simulation from my data with replacement and now, I would like to randomly multiply it by one or negative one, but I am not sure how to do that.
My initial guess was to do the following: y3=y2*randi([-1,1],22528,1000), but I guess it will generate pseudorandom integers in this range, which includes zero. Any suggestion on how to do this will be highly appreciated.
Thanks
Alma

답변 (3개)

jgg
jgg 2016년 2월 22일
편집: jgg 2016년 2월 22일
Try this:
A = [1,-1];
rand_nums = A(randi([1,2],22528,1000));

Azzi Abdelmalek
Azzi Abdelmalek 2016년 2월 22일
편집: Azzi Abdelmalek 2016년 2월 22일
out=2*randi([0 1],22528,1000)-1

Alma Bezares
Alma Bezares 2016년 2월 22일
Thank you so much. The code A = [1,-1]; rand_nums = A(randi([1,2],22528,1000));
did the trick. Thanks!
  댓글 수: 1
jgg
jgg 2016년 2월 22일
You should accept the answer then, so other people can see the solution!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by