Iterative insertion of random numbers in matrix

1 Ansicht (letzte 30 Tage)
Lucas Kellermann
Lucas Kellermann am 26 Jan. 2022
Bearbeitet: David Hill am 26 Jan. 2022
I have a matrix X1.
Now i want to add the sum of two random Numbers
a_x = (-2.5 + (2.5+2.5)*rand(1,1))*1e-9;
l_x = (-2.5 + (2.5+2.5)*rand(1,1))*1e-9;
X1_MC = a_x+l_x
to the value in the first cell of X1.
Then i want to do the same with new random numbers
a_x = (-2.5 + (2.5+2.5)*rand(1,1))*1e-9; % not the same as step1
l_x = (-2.5 + (2.5+2.5)*rand(1,1))*1e-9; % not the same as step1
X1_MC = a_x+l_x
for the secon cell.
I want the process to repeat until the value of each cell in the matrix has been added by two random numbers. The size of X1 is not known
Sorry, I think it is not that compicated but I am new to matlab.

Akzeptierte Antwort

David Hill
David Hill am 26 Jan. 2022
Bearbeitet: David Hill am 26 Jan. 2022
r1=(5*rand(size(X1))-2.5)*1e-9;
r2=(5*rand(size(X1))-2.5)*1e-9;
Xnew=X1+r1+r2;
  3 Kommentare
David Hill
David Hill am 26 Jan. 2022
You are wrong, look at r1 and r2
Lucas Kellermann
Lucas Kellermann am 26 Jan. 2022
Oh yes thanks. So simple haha

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by