random add or subtract a number to an array

3 ビュー (過去 30 日間)
Manikatam Gaddam
Manikatam Gaddam 2019 年 4 月 1 日
コメント済み: Manikatam Gaddam 2019 年 4 月 2 日
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 日
Try this:
a = [1 2 3 4]
r = randi([0, 1], size(a)) - 0.5
b = a + r

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by