Problem 1999. Bleed non-zeros to the right using REGEXP, and that sort of cheatcodess...

This one is quite similar to

But this time you are allowed to use regexp, regexprep, and regexpi. In fact, you are encouraged to do so, since I expect creative solutions, using dynamic regular expressions ( ).

You get a vector, some values and a lot of zeroes. Every zero is replaced by the first non-zero element to its left.

For example, [1 0 0 2 0] becomes [1 1 1 2 2] and [0 0 -12 13 0 i 0 -i 76.54321 0 0] becomes [0 0 -12 13 13 i i -i 76.54321 76.54321 76.54321].

Is it even easier now, or not? Still, eval and friends are forbidden.

Solution Stats

65.0% Correct | 35.0% Incorrect
Last solution submitted on Mar 09, 2016
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more