Problem 960. Cell Source Index
Suppose 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];
Solution Stats
Problem Comments
-
1 Comment
This is a problem where there's probably a good built-in function, but I don't know it.
Solution Comments
Show commentsProblem Recent Solvers38
Suggested Problems
-
How to find the position of an element in a vector without using the find function
2693 Solvers
-
20554 Solvers
-
Back to basics 11 - Max Integer
773 Solvers
-
Replace all zeros and NaNs in a matrix with the string 'error'
97 Solvers
-
Volume difference between Ellipsoid and Sphere
125 Solvers
More from this Author11
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!