Cody

Problem 2601. Concatenate string with cell array of strings

Solution 1686593

Submitted on 5 Dec 2018
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 = {'filename1';'filename2';'filename3'}; b = '_'; ind = 9; c = {'filename_1';'filename_2';'filename_3'}; assert(isequal(cellstrcat(a,b,ind),c))

Assertion failed.

2   Fail
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))

Unable to perform assignment because the left and right sides have a different number of elements. Error in cellstrcat (line 3) a{i}(ind) = b; Error in Test2 (line 5) assert(isequal(cellstrcat(a,b,ind),c))

3   Fail
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))

Unable to perform assignment because the left and right sides have a different number of elements. Error in cellstrcat (line 3) a{i}(ind) = b; Error in Test3 (line 5) assert(isequal(cellstrcat(a,b,ind),c))

4   Fail
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))

Unable to perform assignment because the left and right sides have a different number of elements. Error in cellstrcat (line 3) a{i}(ind) = b; Error in Test4 (line 9) assert(isequal(cellstrcat(a,b,ind),c))