Hello All,
I am trying to randomly add or subtract a constant number to all array elments.
For suppose
a= [1 2 3 4]
b = a + either (0.5 only or -0.5 only)
Is there such possiblity in matlab?

 채택된 답변

Image Analyst
Image Analyst 2019년 4월 2일

1 개 추천

Try this:
a = [1 2 3 4]
r = randi([0, 1], size(a)) - 0.5
b = a + r

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by