📄 seek_eightcycle.m
字号:
function [cycle_position_all find_eight]=seek_eightcycle(H,p)
% clc;clear all;
% H=[1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0;
% 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0;
% 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0;
% 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0;
% 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1;
% 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0;
% 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1;
% 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0;
% 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0;
% 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0;
% 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1;
% 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0;
% 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0;
% 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0;
% 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0];
% dv=3;
% dc=9;
% H_initial=ones(dv,dc);
% p=12;
% S = [0 0 0 0 0 0 0 0 0;
% 0 5 2 6 11 1 8 10 7;
% 0 6 4 1 9 5 2 7 3];
% H=hcreat(H_origin,p,S)
[m,n]=size(H);
%S=[0 0 0 0;0 4 1 2;0 2 3 1];
%p=5;
cycle_position_all=[];find_eight=0;
for l=1:m-p
l;
h_r=H(l,:);
r_index=find(h_r);
L_r=length(r_index);
for i=1:L_r-1
i;
for j=i+1:L_r
j;
h_c=H(l+1:end,r_index(j));%取出第一行中第二个1所在的列,不包括本身
c_index=find(h_c);
c_index=c_index+l;
L_c=length(c_index);
for k=1:L_c
h_r_two=H(c_index(k),:);%取出上述列中各个1所在的行作为第二行
r_index_two=find(h_r_two);
L_r_two=length(r_index_two);
for i2=1:L_r_two
if r_index_two(i2)~=r_index(j)&&r_index_two(i2)~=r_index(i)%如果第二行中1所在的列不等于第二个1所在的列
h_c_two=H(l+1:end,r_index_two(i2));%取出第二行中1所在的列
c_index_two=find(h_c_two);
c_index_two=c_index_two+l;
L_c_two=length(c_index_two);
for j2=1:L_c_two
if c_index_two(j2)~=c_index(k)%如果第二列中1所在的行不等于第二行中1所在的列
h_r_three=H(c_index_two(j2),:);
r_index_three=find(h_r_three);
L_r_three=length(r_index_three);
for i3=1:L_r_three
if r_index_three(i3)~=r_index_two(i2)&&r_index_three(i3)~=r_index(i)
h_c_three=H(l+1:end,r_index_three(i3));
c_index_three=find(h_c_three);
c_index_three=c_index_three+l;
L_c_three=length(c_index_three);
for j3=1:L_c_three
if c_index_three(j3)~=c_index_two(j2)&&H(c_index_three(j3),r_index(i))==1%如果第三列中1所在的行不等于第三行中1所在的列
cycle_position=[l r_index(i);l r_index(j);c_index(k) r_index(j);c_index(k) r_index_two(i2);...
c_index_two(j2) r_index_two(i2);c_index_two(j2) r_index_three(i3);c_index_three(j3) r_index_three(i3);c_index_three(j3) r_index(i)];
cycle_position_all=[cycle_position_all cycle_position];
find_eight=find_eight+1;
end
end
end
end
end
end
end
end
end
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -