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

2 visualizaciones (últimos 30 días)
Md. Mohidul Islam
Md. Mohidul Islam el 25 de Abr. de 2022
Comentada: Torsten el 25 de Abr. de 2022
matrix can only contain one of the only one in his row and column.
  1 comentario
Torsten
Torsten el 25 de Abr. de 2022
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".

Iniciar sesión para comentar.

Respuesta aceptada

Torsten
Torsten el 25 de Abr. de 2022
Editada: Torsten el 25 de Abr. de 2022
[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 comentarios
Md. Mohidul Islam
Md. Mohidul Islam el 25 de Abr. de 2022
What is the problem? how to solve this?

Iniciar sesión para comentar.

Más respuestas (1)

Md. Mohidul Islam
Md. Mohidul Islam el 25 de Abr. de 2022

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by