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

2 次查看(过去 30 天)
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.

更多回答(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