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 ビュー (過去 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)

回答 (2 件)

Youssef  Khmou
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);

muna majeed
muna majeed 2015 年 8 月 4 日
please can help me to add noise to 3d mesh triangle

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by