当前位置: 首页 > 工具软件 > jigsaw-matlab > 使用案例 >

拼图matlab,拼图matlab程序希望有人可以给我讲解一下!!有偿求标注

乐正德华
2023-12-01

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

function pintu1()

ticA = gen()

G = [1 2 3;4 5 6;7 8 0]; drawmap(A); %按照打乱的矩阵显示拼图

while 1

[xpos,ypos] = ginput(1);

col = ceil(xpos);

row = 3-ceil(ypos)+1;

num = A(row,col);

if row>1&A(row-1,col)==0

A(row-1,col) = num;

A(row,col) = 0;

endif row<3&A(row+1,col)==0

A(row+1,col) = num;

A(row,col) = 0;

endif col>1&A(row,col-1)==0

A(row,col-1) = num;

A(row,col) = 0;

endif col<3&A(row,col+1)==0

A(row,col+1) = num;

A(row,col) = 0;

enddrawmap(A)

zt = abs(A-G);if sum(zt(:))==0

msgbox('恭喜您成功完成!')

toc

disp(['运行时间: ',num2str(toc)]);

break

end

endfunction drawmap(A)

clf; %清除当前图形窗图形

hold on

line([0 3],[0 0],'linewidth',4);

line([3 3],[0 3],'linewidth',4);

line([0 3],[3 3],'linewidth',4);

line([0 0],[0 3],'linewidth',4);

for i = 1:3

for j = 1:3

drawrect([j-1 3-i],[j 3-i],[j 3-i+1],[j-1 3-i+1],'y',A(i,j));

end

end

axis equal

axis offfunction drawrect(x1,x2,x3,x4,color,num)

x =[x1(1) x2(1) x3(1) x4(1)];

y = [x1(2) x2(2) x3(2) x4(2)];

fill(x,y,color)

if num==0

text(0.5*(x1(1)+x2(1)),0.5*(x1(2)+x4(2)),'','fontsize',24)

elsetext(0.5*(x1(1)+x2(1))-0.05,0.5*(x1(2)+x4(2)),num2str(num),'fontsize',24)

endfunction y = gen()

y = inf*ones(1,9);

for i = 1:9

while 1

a = randint(1,1,9);

if isempty(find(y==a))

y(i) = a;

break

end

end

end

y = reshape(y,3,3);

 类似资料: