我试图制作一个简单的脚本,可以判断两个棋盘是相似的还是相同的,还是不同的。我必须先测试它是否是相同的大小(例如3x3),因为如果没有,我就不应该首先运行测试。我还必须对第一块板做垂直和水平的翻转,并将它们与第二块板进行比较,看看这两种翻转是否与第二块板匹配。这是我到目前为止掌握的代码:
function similar = symmetric_queens(b1, b2) %b1 is table 1 and b2 is table 2
similar= true;
h1= flipud(b1); %flipping about horizontal axis
v1= fliplr(b1); %flipping about vertical axis
if
b1==b2;
imshow('The boards are identical') %because they are exactly the same
end
if
size(b1)==size(b2) %if they are of equal size test if horizontal flip= second board
h1=b2
imshow('true')
else
v1=h2 %test if vertical flip = second board
imshow('true')
else %in these two codes I am trying to check make the function stop if the boards arent the same size
size(b1)>size(b2)
similar = false;
return;
else
size(b1)<size(b2)
similar = false;
return;
end
end我认为有许多错误,使我的代码不写,任何帮助将是非常感谢的。我很抱歉,如果我没有张贴这个权利,或如果我做了什么错事,因为这是我第一次在这里张贴。
提前感谢!
发布于 2014-04-22 05:49:03
一些有组织的代码,我想做同样的事情-
function similar = symmetric_queens(b1, b2) %b1 is table 1 and b2 is table 2
%%// Check for equal sizes
if ~isequal(size(b1),size(b2))
similar = false;
return;
end
if isequal(b2,b1) %%// Check for perfect match
disp('The boards are identical');
similar = true; %%// What to return for - similar value when they are identical? Assumed - true
elseif isequal(b2,fliplr(b1)) || isequal(b2,flipud(b1)) %%// Check horizontal and vertical flip
disp('The boards are similar');
similar = true;
else
similar = false;
end
return;注意:,我不知道你为什么使用imshow。也许你是说展示短信?密码就是这么做的。
https://stackoverflow.com/questions/23210966
复制相似问题