Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Why do these lines of code not function properly?
조회 수: 1 (최근 30일)
이전 댓글 표시
In this function the first if statement does not work when I provide a matrix with elements larger than 4. I have tried using for loops but that effects the rest of the program for some reason. Also when elseif any(diff(sort(m(:,1))==0)) does in fact equal zero the out is not returned as zero but instead made into one. I spent hours trying to debug it, but I am still having issues. Any assistance is appreciated, thank you.
function out=issudoku(m)
[R,C]=size(m);
if m()>4
out=0;
else if R~=4 || C~=4
out=0;
%Find if any number on the board is not a 1, 2, 3 or 4
%%%see if any number is repeated within the individual squares
elseif m(1,1)==m(2,1)||m(1,1)==m(1,2)||m(1,1)==m(2,2)
out=0;
elseif m(3,1)==m(4,1)||m(3,1)==m(3,2)||m(3,1)==m(4,2)
out=0;
elseif m(1,3)==m(2,3)||m(1,3)==m(1,4)||m(1,3)==m(2,4)
out=0;
elseif m(3,3)==m(4,3)||m(3,3)==m(3,4)||m(3,3)==m(4,4)
out=0;
%repeated numbers within columns:
elseif any(diff(sort(m(:,1))==0))
out=0;
elseif any(diff(sort(m(:,2))==0))
out=0;
elseif any(diff(sort(m(:,3))==0))
out=0;
elseif any(diff(sort(m(:,4))==0))
out=0;
%repeated numbers within rows:
elseif any(diff(sort(m(1,:))==0))
out=0;
elseif any(diff(sort(m(2,:))==0))
out=0;
elseif any(diff(sort(m(3,:))==0))
out=0;
elseif any(diff(sort(m(4,:))==0))
out=0;
else
out=1;
end
end
end
댓글 수: 0
답변 (1개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!