I have a column vector with tens of thousands of entries, and most of these entries are zeros. I am trying to find the most concise code to change the values of zero to the first nonzero value below that particular zero.
Example:
If I have:
A = [0; 0; 15; 0; 0; 0; 5; 0; 0; 0; 0; 0; 3; 0; 0; 0; 0; 9]
Then I would want
A = [15; 15; 15; 5; 5; 5; 5; 3; 3; 3; 3; 3; 3; 9; 9; 9; 9; 9]
Thank you for any help!
Best Answer