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

2 views (last 30 days)
%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)

Answers (2)

Youssef  Khmou
Youssef Khmou on 19 Aug 2013
Edited: Youssef Khmou on 19 Aug 2013
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);

muna majeed
muna majeed on 4 Aug 2015
please can help me to add noise to 3d mesh triangle

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!