📄 arrayfour.asv
字号:
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
% x 是 排好序的 2*2 矩阵的差值阵
% r 是 最小值组成的 1/4 子图片
% b 是 2*2 矩阵排序 中产生的位图
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function [x,r,b]=arrayfour(in)
[s,t]=size(in);
k=1;
for i=1:2:s-1
for j=1:2:t-1
a=in(i:i+1,j:j+1);
a=reshape(a,1,4);
if a(1,1)==a(1,2)==a(1,3)==a(1,4)
x{1,k}=[0 0 0];
r(1,k)=a(1,1);
b{1,k}=[0 0 0];
k=k+1;
else
temp=find(a==min(a));
[m,n]=size(temp);
if n==3
temp1=10-temp(1,1)-temp(1,2)-temp(1,3);
temp2=a(temp1)-a(temp(1,1));
x{1,k}=[0 0,temp2];
r(1,k)=a(temp(1,1));
if temp2>temp(1,3)
b{1,k}=[temp(1,1)-1 temp(1,2)-1 0];
k=k+1;
else
b{1,k}=[temp(1,1)-1 temp(1,2)-1 1];
k=k+1;
end
elseif n==2
temp1=find(a==max(a));
[m1,n1]=size(temp1);
r(1,k)=a(temp(1,1));
if n1==2
x{1,k}=[0 a(temp1(1,1))-a(temp(1,1)) 0];
b{1,k}=[temp(1,1)-1 temp(1,2)-1 0];
k=k+1;
else
temp2=10-temp(1,1)-temp(1,2)-temp1(1,1);
x{1,k}=[0 a(temp2)-a(temp(1,1)) a(temp1(1,1))-a(temp2)];
if temp2>temp1(1,1)
b{1,k}=[temp(1,1)-1 temp(1,2)-1 0];
k=k+1;
else
b{1,k}=[temp(1,1)-1 temp(1,2)-1 1];
k=k+1;
end
end
elseif n==1
r(1,k)=a(temp(1,1));
temp1=find(a==max(a));
[m2,n2]=size(temp1);
if n2==3
x{1,k}=[a(temp1(1,1))-a(temp(1,1)) 0 0];
b{1,k}=[temp(1,1)-1 temp1(1,1)-1 0];
k=k+1;
elseif n2==2
temp2=10-temp(1,1)-temp1(1,1)-temp1(1,2);
x{1,k}=[a(temp2)-a(temp(1,1)) a(temp1(1,1))-a(temp2) 0];
b{1,k}=[temp(1,1)-1 temp2-1 0];
k=k+1;
elseif n2==1
temp3=find(a~=min(a) & a~=max(a));
if a(temp3(1,1))>a(temp3(1,2))
x{1,k}=[a(temp3(1,2))-a(temp(1,1)) a(temp3(1,1))-a(temp3(1,2)) a(temp1(1,1))-a(temp3(1,1))];
if temp3(1,1)>temp1(1,1)
b{1,k}=[temp(1,1)-1 temp3(1,2)-1 0];
k=k+1;
else
b{1,k}=[temp(1,1)-1 temp3(1,2)-1 1];
k=k+1;
end
else
x{1,k}=[a(temp3(1,1))-a(temp(1,1)) a(temp3(1,2))-a(temp3(1,1)) a(temp1(1,1))-a(temp3(1,2))];
if temp3(1,2)>temp1(1,1)
b{1,k}=[temp(1,1)-1 temp3(1,1)-1 0];
k=k+1;
else
b{1,k}=[temp(1,1)-1 temp3(1,1)-1 1];
k=k+1;
end
end
end
end
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -