MATLAB Answers

0

I want to create random bumps on a flat surface

Daniel Gray さんによって質問されました 2017 年 7 月 17 日
最新アクティビティ Daniel Gray さんによって コメントされました 2017 年 7 月 17 日
I have a 300x300 zeros matrix and I would like to create random bumps on the surface on random heights. To be more detailed, imagine circles of ones on the surface, I would like to (rather than those) have bumps on the surface.
Almost like 3D Guassian bumps on the surface.
Any help would be appreciated.

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: Grzegorz Knor 2017 年 7 月 17 日
 採用された回答

You can add Two-dimensional Gaussian functions with random amplitude at random location:
M = zeros(300,300); % initial matrix
N = 3; % number of bumps
sigma = 3;% std (width) of Gauss
maxAmplitude = 5; % maximum height
[x,y] = meshgrid(1:size(M,1),1:size(M,2));
for k=1:N
% random location of bumps
xc = randi(size(M,1));
yc = randi(size(M,2));
% Gauss function
exponent = ((x-xc).^2 + (y-yc).^2)./(2*sigma^2);
amplitude = rand()*maxAmplitude;
% add Gauss to the matrix M
M = M + amplitude*exp(-exponent);
end
surf(M)
shading interp

  1 件のコメント

Daniel Gray 2017 年 7 月 17 日
You're amazing! Thank you

サインイン to comment.



Translated by