Bleed non-zeros to the right using REGEXP, and that sort of cheatcodess... - MATLAB Cody - MATLAB Central

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

Difficulty:Rate

This one is quite similar to http://www.mathworks.nl/matlabcentral/cody/problems/1998-bleed-non-zeros-to-the-right.

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 ( http://www.mathworks.nl/help/matlab/matlab_prog/dynamic-regular-expressions.html ).

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

67.39% Correct | 32.61% Incorrect
Last Solution submitted on Dec 23, 2024

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers27

Suggested Problems

More from this Author31

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!