【发布时间】:2017-06-19 10:30:31
【问题描述】:
使用以下代码,我生成了一个具有 2 个不同斜率的 V 平面,分别为 10° 和 20°。
% /*
% Assumptions
% */
% resolution [m]
res = 1;
% inclination [deg]
i1 = 10; i2 = 20;
% /*
% DEM -> V shape
% */
% pre-allocate output
testDEM = zeros(513);
% required elevation step [m]
hstep = res*tan(i1*(pi/180));
% elevation start right [m]
k = 513*(2/3)*tan(i1*(pi/180));
% coordinates
q = length(1:513*(2/3));
% initialize
nStep = 0;
for jj = 1:q
testDEM(:,jj) = k-nStep;
nStep = nStep + hstep;
end
% change elevation step
step = res*tan(i2*(pi/180));
% update nStep
nStep = step;
% elevation start left [m]
start = testDEM(end,q);
for jj = q+1:513
testDEM(:,jj) = start + nStep;
nStep = nStep + step;
end
testDEM = testDEM(1:507,1:507);
%//Plot test DEM
f_tSlope = figure();
set(gca,'PlotBoxAspectRatio',[1 1 1]);
surf(testDEM, 'EdgeColor', 'none')
colormap jet;
hb = colorbar('location','eastoutside');
hb.Label.String = '[m]';
hb.Label.Rotation = 0;
hb.Label.HorizontalAlignment = 'Left';
通过以下内容,我在每个位置添加噪音
sigma = 1;
testDEM = testDEM + sigma*randn(size(testDEM));
但我想要的是在随机位置添加随机噪声,而不是在任何地方。我该怎么做?
提前致谢
【问题讨论】:
-
你用过randperm吗? mathworks.com/help/matlab/ref/randperm.html
标签: matlab matlab-figure noise