find and replace zeros with a function in matlab
===

once again, sorry if this has been asked before and if its too specific but im very stuck and cant quite find a solution.

i have a matrix of say 3 members of a structure called 2, 4 and 16 (in column 1) that have values along their relative distance e.g. member 2 has values at the start, 0m, then at 0.5m then the end of its length 1.5m, where member 4 starts at 0m etc. so that my matrix looks like this:

    2   0     125
    2   0.5   25
    2   1.5   365
    4   0     25
    4   0.6   57
    16  0     354
    16  0.2   95
    16  0.8   2

and i want to create a matrix that has the overall distance along all the members 2, 4 and 16 combined:

    2   0     125
    2   0.5   25
    2   1.5   365
    4   1.5   25
    4   2.1   57
    16  2.1   354
    16  2.3   95
    16  3.1   2

is there any way to do this in matlab? like possibly locating the first zero and adding the value above it to all the rest of the values below then find the next zero value and so on?

please tell me if this isnt clear, i realise its a bit confusing but not too sure how to explain it better!

thanks!


 