Cody

Solution 1987744

Submitted on 23 Oct 2019
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.m'); assert(isempty(strfind(filetext, 'for'))) assert(isempty(strfind(filetext, 'while')))

2   Fail
x = 'string_'; num1 = 6; n = 3; y_correct = {'string_6' 'string_7' 'string_8'}; assert(isequal(rep_str(x,num1,n),y_correct))

l = 3×8 char array 'string_6' 'string_7' 'string_8' ans = 3 8 y = 3×8 cell array {'s'} {'t'} {'r'} {'i'} {'n'} {'g'} {'_'} {'6'} {'s'} {'t'} {'r'} {'i'} {'n'} {'g'} {'_'} {'7'} {'s'} {'t'} {'r'} {'i'} {'n'} {'g'} {'_'} {'8'} ans = 1 1 1 ans = 8 8 8 8 8 8 8 8

Assertion failed.

3   Fail
x = 'stringX_'; num1 = 2; n = 1; y_correct = {'stringX_2'}; assert(isequal(rep_str(x,num1,n),y_correct))

l = 'stringX_2' ans = 1 9

Error using mat2cell (line 89) Input arguments, D1 through D2, must sum to each dimension of the input matrix size, [1 9]. Error in rep_str (line 6) y=mat2cell(l,[1 1 1],[1 1 1 1 1 1 1 1]) Error in Test3 (line 5) assert(isequal(rep_str(x,num1,n),y_correct))

4   Fail
x = 'stringA_'; num1 = 8; n = 4; y_correct = {'stringA_8' 'stringA_9' 'stringA_10' 'stringA_11'}; assert(isequal(rep_str(x,num1,n),y_correct))

l = 4×10 char array 'stringA_ 8' 'stringA_ 9' 'stringA_10' 'stringA_11' ans = 4 10

Error using mat2cell (line 89) Input arguments, D1 through D2, must sum to each dimension of the input matrix size, [4 10]. Error in rep_str (line 6) y=mat2cell(l,[1 1 1],[1 1 1 1 1 1 1 1]) Error in Test4 (line 8) assert(isequal(rep_str(x,num1,n),y_correct))

5   Fail
x = 'strM_'; num1 = 0; n = 5; y_correct = {'strM_0' 'strM_1' 'strM_2' 'strM_3' 'strM_4'}; assert(isequal(rep_str(x,num1,n),y_correct))

l = 5×6 char array 'strM_0' 'strM_1' 'strM_2' 'strM_3' 'strM_4' ans = 5 6

Error using mat2cell (line 89) Input arguments, D1 through D2, must sum to each dimension of the input matrix size, [5 6]. Error in rep_str (line 6) y=mat2cell(l,[1 1 1],[1 1 1 1 1 1 1 1]) Error in Test5 (line 9) assert(isequal(rep_str(x,num1,n),y_correct))

Suggested Problems

More from this Author57