Given a 2d matrix, say 10×4 with many numbers, lots of which are zeros, I need a matrix that replaces every zero entry with the value of the last non-zero entry in the same column that is before it. for example for the given input:
[0 0 4 0;0 3 1 0;0 0 0 2;0 0 6 2;3 4 5 6;8 0 0 9;0 0 0 0;0 0 0 0;0 0 0 0]output:[0 0 4 0;0 3 1 0;0 3 1 2;0 3 6 2;3 4 5 6;8 4 5 9;8 4 5 9;8 4 5 9;8 4 5 9]
I've experimented with circshift, if statements and for loops but haven't been able to make much headway. Does anyone have suggestions?
Best Answer