How to assign gaussian random numbers on meshgrid?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I have very simple problem regarding assigning gaussian or uniform random numbers, and zeros on each of the meshgrid points. I tried with following way
nx=6;
ny=6;
[x,y]=meshgrid(1:nx,1:ny);
M=[x(:),y(:);zeros(nx,ny)];
M=[x(:),y(:);normrnd(nx,ny)];
However, it does not work. I am missing the correct syntax. Could anyone help me to rectify it?
0 comentarios
Respuestas (2)
Star Strider
el 5 de Ag. de 2017
Try this:
nx=6;
ny=6;
[x,y]=meshgrid(1:nx,1:ny);
zg = randn(size(x)); % Gaussian Random Numbers
zu = rand(size(x)); % Uniform Random Numbers
figure(1)
surf(x,y,zg)
grid on
title('Gaussian Random Numbers')
figure(2)
surf(x,y,zu)
grid on
title('Uniform Random Numbers')
2 comentarios
Star Strider
el 5 de Ag. de 2017
The figures are simply to demonstrate the code.
The ‘zg’ and ‘zu’ arrays are the assignments you want.
Walter Roberson
el 5 de Ag. de 2017
You have
nx=6;
ny=6;
[x,y]=meshgrid(1:nx,1:ny);
After that, x and y are going to be 6 x 6.
Then you have
M=[x(:),y(:);zeros(nx,ny)];
The x(:) part is going to reshape the 6 x 6 x array into (6*6) x 1 . The y(:) is going to reshape the 6 x 6 y array into (6*6) x 1. The x(:),y(:) is therefore going to be 36 x 2
The zeros(nx,ny) is going to be 6 x 6.
Now, you are using ";" between those parts, so you are trying to put the 6 x 6 array "below" the 36 x 2 array.
If you need an array with x and y and z coordinates for some reason, then I would suggest
M=[x(:), y(:), zeros(nx*ny, 1)];
1 comentario
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!