How do i add a random number to each matrix element in matlab? -


i have following matrix x , column vector h:

 x=[ 1 2 3; 2 3 4; 3 4 5];  h=[1; 2 ;3];  m=[x(:,1) h(:) x(:,2) h(:) x(:,3) h(:)]; 

how add small random number elements of m while keeping every column h in matrix m same after adding random number?

you should add random numbers separately, , build combined matrix.

xnew = x + rand(size(x)); % replace 'rand' random numbers want hnew = h + rand(size(h)); mnew = [xnew(:,1) hnew(:) xnew(:,2) hnew(:) xnew(:,3) hnew(:)]; 

Comments