Cody

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

Solution 1001735

Submitted on 8 Oct 2016 by Jang geun Choi
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
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))

B = 3×3 cell array 'yes' 'no' 'maybe' 'no' 'maybe' 'yes' 'maybe' 'yes' 'no'

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

B = 1×20 cell array Columns 1 through 8 'apples' 'apples' 'apples' 'apples' 'apples' 'apples' 'apples' 'apples' Columns 9 through 16 'apples' 'apples' 'apples' 'apples' 'apples' 'apples' 'apples' 'apples' Columns 17 through 20 'apples' 'apples' 'apples' 'apples'

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

B = 22×10 cell array '656' '635' '925' '494' '566' '469' '476' '313' '109' '743' '178' '815' '665' '328' '912' '509' '109' '584' '434' '817' '877' '278' '161' '9' '14' '614' '409' '749' '101' '201' '577' '432' '462' '730' '620' '693' '332' '9' '974' '362' '856' '313' '599' '639' '876' '536' '836' '887' '352' '679' '65' '79' '241' '960' '764' '693' '670' '941' '126' '384' '174' '719' '871' '135' '665' '332' '707' '114' '317' '200' '663' '804' '832' '486' '118' '530' '26' '175' '671' '540' '448' '410' '480' '100' '326' '597' '468' '668' '818' '737' '446' '867' '368' '837' '878' '937' '558' '641' '459' '904' '528' '247' '688' '965' '237' '713' '977' '505' '885' '439' '208' '628' '898' '988' '865' '66' '878' '121' '833' '68' '765' '725' '271' '904' '119' '893' '420' '219' '738' '80' '480' '905' '352' '363' '984' '380' '349' '812' '464' '630' '191' '138' '436' '847' '667' '183' '684' '778' '841' '683' '606' '850' '988' '567' '255' '369' '539' '14' '8' '455' '558' '940' '34' '705' '937' '736' '553' '645' '365' '951' '414' '945' '395' '410' '840' '62' '449' '983' '200' '277' '645' '620' '187' '973' '223' '469' '128' '306' '715' '648' '150' '561' '668' '48' '32' '686' '918' '927' '859' '335' '960' '480' '735' '386' '159' '849' '205' '835' '406' '462' '2' '648' '56' '191' '256' '9' '63' '485' '377' '878'

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

B = 1×100 cell array Columns 1 through 14 '1' '0' '0' '1' '1' '0' '1' '0' '0' '0' '0' '0' '1' '0' Columns 15 through 28 '0' '1' '1' '1' '0' '1' '1' '1' '1' '1' '0' '1' '0' '0' Columns 29 through 42 '0' '0' '1' '0' '0' '1' '1' '1' '1' '1' '0' '0' '0' '1' Columns 43 through 56 '0' '0' '1' '0' '0' '1' '0' '1' '0' '1' '1' '1' '0' '1' Columns 57 through 70 '1' '0' '0' '0' '1' '1' '0' '1' '1' '0' '1' '0' '0' '1' Columns 71 through 84 '1' '1' '1' '1' '1' '1' '1' '0' '1' '1' '1' '0' '0' '0' Columns 85 through 98 '0' '1' '1' '1' '0' '1' '0' '1' '0' '0' '1' '1' '0' '0' Columns 99 through 100 '1' '0'

5   Pass
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))

B = 1×6 cell array 'bar' 'qux' 'qux' 'bar' 'bar' 'qux'