Sum if conditions are satisfied across arrays
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Abhishek Varghese
el 14 de Feb. de 2018
Editada: Abhishek Varghese
el 14 de Feb. de 2018
Hello everyone,
Kinda stuck. Scenario is:
I have a binary 2D array that is n rows and m columns.
I want to count how many times an element went from being a '1' in one row, to a '0' in the next row, and store it as a vector.
I have updated an illustration to help.
Would really appreciate an efficient and simple solution, cheers.
2 comentarios
Matt J
el 14 de Feb. de 2018
I have a binary 2D array that is m rows and n columns.
According to your diagram, n is the number of rows, not columns.
Respuesta aceptada
Matt J
el 14 de Feb. de 2018
Editada: Matt J
el 14 de Feb. de 2018
result = sum(diff(array,1,1)==-1 ,1)
3 comentarios
Matt J
el 14 de Feb. de 2018
In that case,
result = sum( diff(array,1,1)==-1 ,2)
Abhishek Varghese
el 14 de Feb. de 2018
Editada: Abhishek Varghese
el 14 de Feb. de 2018
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!