求MATLAB高手呀?
這個怎麼做。。本人已快暈
%% file1: gauss_000.m
function p=gauss_000(x,mu,sigma)
p=1/sqrt(2*pi*sigma)*exp(-(x-mu).^2/2/sigma^2);
end
%% file2: generate_gauss_filter_000.m
function [p,h]=generate_gauss_filter_000(order,sigma)
x=(-floor(order/2):floor(order/2));
p=gauss_000(x,0,sigma);
p=p/sum(p);
h=kron(p,p);
end
%% file3: filter_1D_000.m
function y=filter_1D_000(x,p)
order=floor(numel(p)/2);
x=[zeros(1,order) x zeros(1,order)];
y=0;
for i=1:order*2+1
y=y+p(i)*x(i+(0:numel(x)-order*2-1));
end
end
%% file4: filter_2D_000.m
function y=filter_2D_000(x,h)
order=floor(sqrt(numel(h))/2);
[m,n]=size(x);
x=[zeros(order,order*2+n);zeros(m,order) x zeros(m,order);zeros(order,order*2+n)];
y=0;
for i=1:order*2+1
for j=1:order*2+1
y=y+h(i,j)*x(i+(0:m-1),j+(0:n-1));
end
end
end
%% file5: exer_1D_000.m
x1D=randn(1,500);
p1=generate_gauss_filter_000(7,1);
p2=generate_gauss_filter_000(7,10);
y1D1=filter_1D_000(x1D,p1);
y1D2=filter_1D_000(x1D,p2);
figure(1)
clf
plot(1:numel(x1D),x1D,1:numel(x1D),y1D1,1:numel(x1D),y1D2,linewidth,2)
legend(unfiltered,sigma=1,sigma=10)
%% file6: exer_2D_000.m
x2D=randn(50,60);
[~,h1]=generate_gauss_filter_000(7,1);
[~,h2]=generate_gauss_filter_000(7,10);
y2D1=filter_2D_000(x2D,h1);
y2D2=filter_2D_000(x2D,h2);
limit1=[min(min([x2D y2D1 y2D2])) max(max([x2D y2D1 y2D2]))];
figure(2)
pcolor(x2D)
shading(flat)
caxis(limit1)
colorbar
figure(3)
pcolor(y2D1)
shading(flat)
caxis(limit1)
colorbar
figure(4)
pcolor(y2D2)
shading(flat)
caxis(limit1)
colorbar
推薦閱讀:
※MATLAB算符重載和量綱分析
※Matlab 64位安裝時顯示 VC2005 error 1935?
※Lingo和Matlab在解決最優化問題的時候的優缺點?
※MATLAB手動跳出循環的技巧
※如何實現多維數組的行 / 列按照 index 訪問都得到連續內存?
TAG:MATLAB |