generate random number between positive and negative and sum of this number is zero
조회 수: 7 (최근 30일)
이전 댓글 표시
I want generate random number between positive and negative, and then the sum of this number equal to zero. what have I should do?
댓글 수: 0
채택된 답변
추가 답변 (1개)
Voss
2022년 4월 12일
x = randn(); % random number from standard Normal distribution
y = -x; % another number such that the sum of x and y is 0
x
y
x+y
댓글 수: 2
Voss
2022년 4월 12일
x = randn(5); % 5x5 random matrix from standard Normal distribution
y = -x; % another matrix such that the sum of x and y is 0
x
y
x+y
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!