Cody

# Problem 1741. Numeric array to cell array of strings (easy)

Solution 1039747

Submitted on 31 Oct 2016
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   Fail
A = [1 2 3 2 3 1 3 1 2]; C = {'yes','no','maybe'}; B_correct = {'yes' 'no' 'maybe' 'no' 'maybe' 'yes' 'maybe' 'yes' 'no'}; assert(isequal(ind2str(A,C),B_correct))

Conversion to cell from char is not possible. Error in ind2str (line 5) B(A==i) = C{i}; Error in TestPoint1 (line 8) assert(isequal(ind2str(A,C),B_correct))

2   Fail
A = ones(20,1); C = {'apples','oranges'}; assert(all(strcmp(ind2str(A,C),'apples')))

Conversion to cell from char is not possible. Error in ind2str (line 5) B(A==i) = C{i}; Error in TestPoint2 (line 3) assert(all(strcmp(ind2str(A,C),'apples')))

3   Fail
A = randi(1000,[22,10]); C = arrayfun(@(x) num2str(x),1:1000,'uni',0); assert(isequal(A,cellfun(@(c) str2num(c),ind2str(A,C))))

Conversion to cell from char is not possible. Error in ind2str (line 5) B(A==i) = C{i}; Error in TestPoint3 (line 3) assert(isequal(A,cellfun(@(c) str2num(c),ind2str(A,C))))

4   Fail
A = randi(2,[1,100]); C = {'0','1'}; assert(isequal(A-1,cellfun(@(c) str2num(c),ind2str(A,C))))

Conversion to cell from char is not possible. Error in ind2str (line 5) B(A==i) = C{i}; Error in TestPoint4 (line 3) assert(isequal(A-1,cellfun(@(c) str2num(c),ind2str(A,C))))

5   Fail
A = [2 4 4 2 2 4]; C = {'foo','bar','baz','qux'}; B_correct = {'bar' 'qux' 'qux' 'bar' 'bar' 'qux'}; assert(isequal(ind2str(A,C),B_correct))

Conversion to cell from char is not possible. Error in ind2str (line 5) B(A==i) = C{i}; Error in TestPoint5 (line 4) assert(isequal(ind2str(A,C),B_correct))