How to apply a random number to every cell in matrix - Matlab -


I want to apply randomity for each element in my matrix. I have provided a MWE below.

  x_len = 1000; Y_len = 100; X = 0: 1: x_len; Y = 0: 1: y_len; [X, y] = meshagrid (x, y); Z = (0.04 * X); I for = 1: (x_len * y_len) rand = rand (); Z = Z + RAND; End  

This implements the same random number in each cell in the bar exactly the matrix (x_len * y_len) . I want to add each cell to a different random number. I have searched, and feel that this is a simple thing, but I have failed to recognize the necessary syntax thanks. AM

If I understand correctly, then you can just type:

  Z = Z + rand (size (z));  

Where Z is your M-by-N matrix.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -