Add terms surrounded by zero together in matrix

*To*: mathgroup at smc.vnet.net*Subject*: [mg59123] Add terms surrounded by zero together in matrix*From*: "mchangun at gmail.com" <mchangun at gmail.com>*Date*: Fri, 29 Jul 2005 00:42:08 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

Hi All, I think this is a rather tough problem to solve. I'm stumped and would really appreciated it if someone can come up with a solution. What i want to do is this. Suppose i have the following matrix: 0 0 0 1 0 0 0 1 2 0 0 0 0 2 1 1 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 5 0 3 0 0 0 0 0 0 0 0 0 0 3 1 I'd like to go through it and sum the elements which are surrounded by zeros. So for the above case, an output: [7 4 5 5 4] is required. The order in which the groups surrounded by zero is summed does not matter. The elements are always integers greater than 0. Thanks for any help!

**Follow-Ups**:**Re: Add terms surrounded by zero together in matrix***From:*Andrzej Kozlowski <akoz@mimuw.edu.pl>

**Re: Add terms surrounded by zero together in matrix***From:*"Fred Simons" <f.h.simons@tue.nl>