Add or subtract 0.1 randomly to all elements of a matix

6 次查看(过去 30 天)
Hi. Good day.
I would like you to help me solve the following:
I have a 3 X 6 matrix
A = [0.36 0.12 0.70 0.32 0.39 0.64
0.07 0.69 0.27 0.06 0.49 0.49
0.70 0.39 0.85 0.75 0.57 0.36]
I would like to add(+) or subtract(-) 0.1 randomly, to each and every one of the elements of matrix A
How can I do it?
Thank you

采纳的回答

Bruno Luong
Bruno Luong 2019-8-26
编辑:Bruno Luong 2019-8-26
A + 0.1*(2*(rand(size(A))>0.5)-1)
or
A + 0.1*(2*(randi([0,1],size(A)))-1)
  3 个评论
Quinty van der Heijden
Can you also let matlab substract or add a random number between for example 0.1 and 0.3 for every element of the matrix?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by