How to check 0 and 1 at matrix every row and column?

조회 수: 4 (최근 30일)
Md. Mohidul Islam
Md. Mohidul Islam 2022년 4월 25일
댓글: Torsten 2022년 4월 25일
matrix can only contain one of the only one in his row and column.
  댓글 수: 1
Torsten
Torsten 2022년 4월 25일
If you know that the matrix contains only 0's and 1's, sum the rows and sum the columns. If the result is 1 in each case, return "correct".

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2022년 4월 25일
편집: Torsten 2022년 4월 25일
[m,n] = size(A);
Sc = sum(A,1);
Sr = sum(A,2);
if (Sc == ones(1,n)) & (Sr == ones(m,1))
disp('Correct')
else
disp('Incorrect')
end
I leave the input-from-keyboard part to you.
  댓글 수: 3
Md. Mohidul Islam
Md. Mohidul Islam 2022년 4월 25일
What is the problem? how to solve this?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Md. Mohidul Islam
Md. Mohidul Islam 2022년 4월 25일

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by