MATLAB如何制作函数?
im1=imread('1.bmp');angle=30;pai=3.14;subplot(211);imshow(im1);title('原始图像');roteang=...
im1=imread('1.bmp');angle=30;pai=3.14;subplot(211);imshow(im1);title('原始图像');roteang=angle/180*pi;[im1X,im1Y]=size(im1);%计算旋转矩阵rotmatrix=[cos(roteang),-sin(roteang);sin(roteang),cos(roteang)];%计算反旋转矩阵rrotmatrix=[cos(-roteang),-sin(-roteang);sin(-roteang),cos(-roteang)];%计算新图像大小,以及新图像的1,1精确定位点im2XY1=[im1X,im1Y]*rotmatrix;im2XY2=[im1X,1]*rotmatrix;im2XY3=[1,1]*rotmatrix;im2XY4=[1,im1Y]*rotmatrix;im2p11=[min([im2XY1(1),im2XY2(1),im2XY3(1),im2XY4(1)]),min([im2XY1(2),im2XY2(2),im2XY3(2),im2XY4(2)])];im2X=round(max([im2XY1(1),im2XY2(1),im2XY3(1),im2XY4(1)])-im2p11(1));im2Y=round(max([im2XY1(2),im2XY2(2),im2XY3(2),im2XY4(2)])-im2p11(2));%建立新图像im2=uint8(zeros(im2X,im2Y))+255;%对于每个像素点,进行上文所述的计算。for i=1:im2X for j=1:im2Y pij=round([i+im2p11(1)-1,j+im2p11(2)-1]*rrotmatrix); if (pij(1)>=1)&&(pij(2)>=1)&&(pij(1)<=im1X)&&(pij(2)<=im1Y) im2(i,j)=im1(pij(1),pij(2)); end endend;%绘制新图subplot(212);imshow(im2);这是程序怎么做成M文件,也就是函数的形式呢?请高人指教。。
展开
2个回答
展开全部
给你看个例子,这个文件名是m_sequence.m,内容如下:
function mseq = m_sequence(fbconnection);
%m序列成器
%输入参数为fbconnection,输出参数为mseq
n = length(fbconnection);
N = 2^n-1;
register = [zeros(1,n - 1) 1];%定义移位寄存器的初始状态
mseq(1)= register(1);
for i = 2:N
newregister(n)= mod(sum(fbconnection.*register),2);
for j = 2:n
newregister(j-1)= register(j);
end
register = newregister;
mseq(i) = register(1);
end
return;
function mseq = m_sequence(fbconnection);
%m序列成器
%输入参数为fbconnection,输出参数为mseq
n = length(fbconnection);
N = 2^n-1;
register = [zeros(1,n - 1) 1];%定义移位寄存器的初始状态
mseq(1)= register(1);
for i = 2:N
newregister(n)= mod(sum(fbconnection.*register),2);
for j = 2:n
newregister(j-1)= register(j);
end
register = newregister;
mseq(i) = register(1);
end
return;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |