Problem 43181. Find index of a string in a cell array

Solution 1043907

Submitted on 4 Nov 2016 by Alfonso Nieto-Castanon
  • Size: 12
  • This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x = {'twenty-one'; 'twenty-two'; 'twenty-three'; 'one'; 'two'; 'three'}; for i = 1:6 assert(isequal(cellfind(x{i}, x),i)) validatestring(x{cellfind(x{i}, x)}, {x{i}}) end

ans = twenty-one ans = twenty-two ans = twenty-three ans = one ans = two ans = three

Suggested Problems

More from this Author15

Community Treasure Hunt

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

Start Hunting!