I created an 3D sinusoidal surface. And want to add a normally distributed random noise of zero mean and 0.03mm standard deviation. But it said error on the line with*. Subscripted assignment dimension mismatch. could someone help me check it please
1 次查看(过去 30 天)
显示 更早的评论
%3D sinusoidal surface dx=0.001; %spacing in x in mm dy=0.001; %number of points along x and y nx=128; ny=128; %n=8000; %generate array of x & y x=(0:1:nx-1)*dx; y=(0:1:ny-1)*dy; for j=1:ny for i=1:nx z(j,i)=2*sin(2*pi*x(i)/0.064)+normrnd(0,0.03*ones(nx,1)); end end z=z-mean(mean(z));%shift to 0 mean mesh(x,y,z)
0 个评论
回答(2 个)
Youssef Khmou
2013-8-19
编辑:Youssef Khmou
2013-8-19
Jianxiang,
As you use x,y loops , at each iteration the CPU computes only one scalar while you used the function normrnd of size 128*1, you can adjust your method :
%3D sinusoidal surface
dx=0.001; %spacing in x in mm
dy=0.001; %number of
%points along x and y
nx=128; ny=128; %
n=8000; %generate array of x & y
x=(0:1:nx-1)*dx;
y=(0:1:ny-1)*dy;
for j=1:ny
for i=1:nx
z(j,i)=2*sin(2*pi*x(i)/0.064)+normrnd(0,0.03);
end
end
z=z-mean(mean(z));%shift to 0 mean mesh(x,y,z)
Or you can simply add the Gaussian noise like the following :
Z=z+normrnd(0,0.03,nx,ny);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!