将图像矩阵设为1.txt
2 3 1 3 5 5 5 5 5 5 5 3 4 4 4 4
3 3 1 2 3 4 5 5 5 5 4 4 3 4 4 3
2 2 3 1 2 4 2 5 5 4 4 4 4 3 3 3
1 2 3 3 1 4 3 4 3 2 3 4 4 4 3 3
1 3 1 3 1 1 4 3 2 3 3 3 3 3 3 3
2 2 3 1 2 1 3 1 2 3 4 3 3 3 3 3
2 3 3 2 1 2 2 3 2 3 3 3 3 3 3 3
1 1 3 1 1 1 2 2 2 2 3 3 5 4 3 3
2 2 2 1 1 2 2 2 1 2 4 2 3 3 3 4
1 1 2 2 1 1 3 2 2 2 1 3 3 1 2 3
1 1 1 1 1 1 2 1 1 1 1 2 3 3 3 3
2 1 1 1 1 2 2 2 1 1 2 3 3 1 3 4
2 2 1 1 1 1 1 2 1 1 4 3 2 3 2 3
1 2 1 1 2 1 1 2 1 2 1 3 2 3 3 3
2 1 2 2 1 1 4 2 1 1 1 2 2 3 2 4
3 2 1 1 2 3 2 1 2 1 1 1 1 2 2 1
按列进行游程编码,Matlab以列优先。
所以,先将原矩阵转置
代码
B=load('1.txt') ; %读矩阵
A=B' ; %矩阵转置
for i=1:16 %循环判断
for j=1:15
if A(j+1,i)~=A(j,i) %比较前后是否相同
n=i;
l=j;
m=A(j,i);
fprintf('%d\t',n,l,m) %输出
fprintf('\n')
end
end
end
前面为位置,列号行号,第三位为数值。(也就是原矩阵的行列号和数值)
在Excel表格中整理一下,得到最后结果。
1 | 1 | 2 | 2 | 2 | 3 | 3 | 2 | 2 | 4 | 1 | 1 |
1 | 2 | 3 | 2 | 3 | 1 | 3 | 3 | 3 | 4 | 2 | 2 |
1 | 3 | 1 | 2 | 4 | 2 | 3 | 4 | 1 | 4 | 4 | 3 |
1 | 4 | 3 | 2 | 5 | 3 | 3 | 5 | 2 | 4 | 5 | 1 |
1 | 11 | 5 | 2 | 6 | 4 | 3 | 6 | 4 | 4 | 6 | 4 |
1 | 12 | 3 | 2 | 10 | 5 | 3 | 7 | 2 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| 12 | 3 | 10 | 15 | 2 | 15 | 14 | 3 | 16 | 2 | 2 |
13 | 13 | 2 | 14 | 1 | 1 | 15 | 15 | 2 | 16 | 4 | 1 |
13 | 14 | 3 | 14 | 2 | 2 | 16 | 5 | 2 | |||
13 | 15 | 2 | 14 | 4 | 1 | 16 | 6 | 3 | |||
14 | 5 | 2 | 16 | 7 | 2 | ||||||
14 | 7 | 1 | 16 | 8 | 1 | ||||||
14 | 8 | 2 | 16 | 9 | 2 | ||||||
14 | 9 | 1 | 16 | 13 | 1 | ||||||
14 | 10 | 2 | 16 | 15 | 2 | ||||||
14 | 11 | 1 | |||||||||
14 | 12 | 3 | |||||||||
14 | 13 | 2 |