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 1755. Fix the last element of a cell array

Created by Ned Gulley

Note: this is lifted directly from Puzzler for a Monday (on MATLAB Answers) by the cyclist.


Given a cell array of strings


and a particular string value


ensure that B is the last element of the cell array. If it isn't, move it to the end of A.

You cannot assume that B appears at all (in which case return A unchanged), but you can assume B does not appear more than once.

So in the example,


Problem Group

Solution Statistics

36 correct solutions 20 incorrect solutions
Last solution submitted on Jun 23, 2015