Increassing an array by a random value
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello guys,
lets say I have 3 arrays and 3 random numbers that I use to increase elements in the 3 arrays. Something like this:
a = rand()*(2)-1;
b = rand()*(2)-1;
c = rand()*(2)-1;
X = [1...10];
Y = [11...20];
Z = [21...30];
Now the easiest way to increase the elements in arrays by those number would be:
X1 = X+a
Y1 = Y+b
Z1 = Z+c
My question is if there is a way to add those random numbers randomly, so it will alway choose a random number from a,b,c to every array
댓글 수: 0
채택된 답변
Walter Roberson
2021년 2월 16일
a = rand()*(2)-1;
b = rand()*(2)-1;
c = rand()*(2)-1;
abc = [a,b,c]
X = [1:10];
Y = [11:20];
Z = [21:30];
XYZ = [X;Y;Z];
ridx = randi(3, size(XYZ))
XYZ = XYZ + abc(ridx);
X1 = XYZ(1,:)
Y1 = XYZ(2,:)
Z1 = XYZ(3,:)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!