Add or subtract 0.1 randomly to all elements of a matix

조회 수: 6 (최근 30일)
Ricardo Gutierrez
Ricardo Gutierrez 2019년 8월 26일
댓글: Bruno Luong 2021년 4월 29일
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
Quinty van der Heijden 2021년 4월 29일
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?
Bruno Luong
Bruno Luong 2021년 4월 29일
Hint for you
0.1 = 0.2 - 0.1
0.3 = 0.2 + 0.1

댓글을 달려면 로그인하십시오.

추가 답변 (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