Cody

# Problem 2601. Concatenate string with cell array of strings

Solution 1947472

Submitted on 24 Sep 2019 by Nikolaos Nikolaou
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 = {'filename1';'filename2';'filename3'}; b = '_'; ind = 9; c = {'filename_1';'filename_2';'filename_3'}; assert(isequal(cellstrcat(a,b,ind),c))

t = 'filename1' c = 1×1 cell array {'filename_1'} t = 'filename2' c = 1×2 cell array {'filename_1'} {'filename_2'} t = 'filename3' c = 1×3 cell array {'filename_1'} {'filename_2'} {'filename_3'} c = 3×1 cell array {'filename_1'} {'filename_2'} {'filename_3'}

2   Pass
a = {'1';'2';'3';'4';'5'}; b = 'filename_'; ind = 1; c = {'filename_1';'filename_2';'filename_3';'filename_4';'filename_5'}; assert(isequal(cellstrcat(a,b,ind),c))

t = '1' c = 1×1 cell array {'filename_1'} t = '2' c = 1×2 cell array {'filename_1'} {'filename_2'} t = '3' c = 1×3 cell array {'filename_1'} {'filename_2'} {'filename_3'} t = '4' c = 1×4 cell array {'filename_1'} {'filename_2'} {'filename_3'} {'filename_4'} t = '5' c = 1×5 cell array {'filename_1'} {'filename_2'} {'filename_3'} {'filename_4'} {'filename_5'} c = 5×1 cell array {'filename_1'} {'filename_2'} {'filename_3'} {'filename_4'} {'filename_5'}

3   Pass
a = {'foo';'bar';'baz';'qux'}; b = '.mat'; ind = 4; c = {'foo.mat';'bar.mat';'baz.mat';'qux.mat'}; assert(isequal(cellstrcat(a,b,ind),c))

t = 'foo' c = 1×1 cell array {'foo.mat'} t = 'bar' c = 1×2 cell array {'foo.mat'} {'bar.mat'} t = 'baz' c = 1×3 cell array {'foo.mat'} {'bar.mat'} {'baz.mat'} t = 'qux' c = 1×4 cell array {'foo.mat'} {'bar.mat'} {'baz.mat'} {'qux.mat'} c = 4×1 cell array {'foo.mat'} {'bar.mat'} {'baz.mat'} {'qux.mat'}

4   Pass
a = {'data1','data23','data456','data7890'}; d = datestr(now,'yyyymmdd'); b = strcat('_',d,'_'); ind = 5; c{1} = ['data_',d,'_1']; c{2} = ['data_',d,'_23']; c{3} = ['data_',d,'_456']; c{4} = ['data_',d,'_7890']; assert(isequal(cellstrcat(a,b,ind),c))

t = 'data1' c = 1×1 cell array {'data_20190924_1'} t = 'data23' c = 1×2 cell array {'data_20190924_1'} {'data_20190924_23'} t = 'data456' c = 1×3 cell array {'data_20190924_1'} {'data_20190924_23'} {'data_20190924_456'} t = 'data7890' c = 1×4 cell array {'data_20190924_1'} {'data_20190924_23'} {'data_20190924_456'} {'data_20190924_7890'} c = 1×4 cell array {'data_20190924_1'} {'data_20190924_23'} {'data_20190924_456'} {'data_20190924_7890'}