Cody

# Problem 42484. Repeat string n times - 2

Solution 1609777

Submitted on 15 Aug 2018 by Srishti Saha
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
filetext = fileread('rep_str_2.m'); assert(isempty(strfind(filetext, 'for'))) assert(isempty(strfind(filetext, 'while')))

2   Pass
x = 'str_'; num1 = 4; num2 = 10; n = 4; y_correct = {'str_4_10' 'str_5_11' 'str_6_12' 'str_7_13'}; assert(isequal(rep_str_2(x, num1, num2, n),y_correct))

nbrs1 = 4 5 6 7 nbrs1 = 1×4 string array "4" "5" "6" "7" nbrs2 = 10 11 12 13 nbrs2 = 1×4 string array "10" "11" "12" "13" x = 'str_' y = 1×4 string array "str_4_10" "str_5_11" "str_6_12" "str_7_13" y = 4×1 string array "str_4_10" "str_5_11" "str_6_12" "str_7_13" y = 4×1 cell array {'str_4_10'} {'str_5_11'} {'str_6_12'} {'str_7_13'}

3   Pass
x = 'matstr_'; num1 = 0; num2 = 50; n = 3; y_correct = {'matstr_0_50' 'matstr_1_51' 'matstr_2_52'}; assert(isequal(rep_str_2(x, num1, num2, n),y_correct))

nbrs1 = 0 1 2 nbrs1 = 1×3 string array "0" "1" "2" nbrs2 = 50 51 52 nbrs2 = 1×3 string array "50" "51" "52" x = 'matstr_' y = 1×3 string array "matstr_0_50" "matstr_1_51" "matstr_2_52" y = 3×1 string array "matstr_0_50" "matstr_1_51" "matstr_2_52" y = 3×1 cell array {'matstr_0_50'} {'matstr_1_51'} {'matstr_2_52'}

4   Pass
x = 'matstr2_'; num1 = 2; num2 = 3; n = 1; y_correct = {'matstr2_2_3'}; assert(isequal(rep_str_2(x, num1, num2, n),y_correct))

nbrs1 = 2 nbrs1 = "2" nbrs2 = 3 nbrs2 = "3" x = 'matstr2_' y = "matstr2_2_3" y = "matstr2_2_3" y = 1×1 cell array {'matstr2_2_3'}