Discover MakerZone

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

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!

Problem 1998. Bleed non-zeros to the right

Created by J-G van der Toorn

What a title! Yet, it says what I mean.

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].

Easy, isn't it?

Regexp, regexprep, regexpi, eval, evalc, evalin, nor inline are allowed this time.

(This problem is related to


Problem Group

Solution Statistics

18 correct solutions 13 incorrect solutions
Last solution submitted on Jun 23, 2015

Problem Comments