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

Learn moreOpportunities for recent engineering grads.

Apply TodaySuppose that C is a cell array whose elements consist of row vectors of elements of the same type. For example, C could be a cell vector of strings:

C = {'abc' 'd' 'ef' 'ghij'};

We can put all the elements from all the vectors of C into a single vector:

VC = [C{:}];

Your task: write a function that returns a vector iC, where each element of iC holds the index of the element of C from which the corresponding element of VC came. For example, if C has the value given above, then this would be the correct contents for iC:

iC = [1 1 1 2 3 3 4 4 4 4];

35 correct solutions
40 incorrect solutions

Last solution submitted on Jun 15, 2014

1 player likes this problem

1 Comment

Aurelien Queffurust
on 8 Nov 2012

this will be hard to beat !

1 Comment