random add or subtract a number to an array

3 visualizaciones (últimos 30 días)
Manikatam Gaddam
Manikatam Gaddam el 1 de Abr. de 2019
Comentada: Manikatam Gaddam el 2 de Abr. de 2019
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?

Respuesta aceptada

Image Analyst
Image Analyst el 2 de Abr. de 2019
Try this:
a = [1 2 3 4]
r = randi([0, 1], size(a)) - 0.5
b = a + r

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by