Cody

# Problem 967. Split a string into chunks of specified length

Solution 3312463

Submitted on 21 Oct 2020
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
s = 'Easy'; b = ones(1,4); y_correct = {'E','a','s','y'}; assert(isequal(break_string(s,b),y_correct))

y = 4×1 cell array {0×0 double} {0×0 double} {0×0 double} {0×0 double}

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in break_string (line 5) y{i} = s(B(i-1),B(i)); Error in Test1 (line 4) assert(isequal(break_string(s,b),y_correct))

2   Fail
s = 'I seem to be having tremendous difficulty with my lifestyle'; b = [4 1 5 22]; y_correct = {'I se','e','m to ','be having tremendous d'}; assert(isequal(break_string(s,b),y_correct))

y = 4×1 cell array {0×0 double} {0×0 double} {0×0 double} {0×0 double}

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in break_string (line 5) y{i} = s(B(i-1),B(i)); Error in Test2 (line 4) assert(isequal(break_string(s,b),y_correct))

3   Fail
s = 'The answer is 42'; b = [4 7 3]; y_correct = {'The ','answer ','is '}; assert(isequal(break_string(s,b),y_correct))

y = 3×1 cell array {0×0 double} {0×0 double} {0×0 double}

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in break_string (line 5) y{i} = s(B(i-1),B(i)); Error in Test3 (line 4) assert(isequal(break_string(s,b),y_correct))

4   Fail
s = 'Did I do that?'; b = [2 3 3]; y_correct = {'Di','d I',' do'}; assert(isequal(break_string(s,b),y_correct))

y = 3×1 cell array {0×0 double} {0×0 double} {0×0 double}

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in break_string (line 5) y{i} = s(B(i-1),B(i)); Error in Test4 (line 4) assert(isequal(break_string(s,b),y_correct))

5   Fail
s = 'Yes no when?'; b = [2 6 3]; y_correct = {'Ye','s no w','hen'}; assert(isequal(break_string(s,b),y_correct))

y = 3×1 cell array {0×0 double} {0×0 double} {0×0 double}

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in break_string (line 5) y{i} = s(B(i-1),B(i)); Error in Test5 (line 4) assert(isequal(break_string(s,b),y_correct))

6   Fail
s = 'Hello there'; b = [3 4 4]; y_correct = {'Hel','lo t','here'}; assert(isequal(break_string(s,b),y_correct))

y = 3×1 cell array {0×0 double} {0×0 double} {0×0 double}

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in break_string (line 5) y{i} = s(B(i-1),B(i)); Error in Test6 (line 4) assert(isequal(break_string(s,b),y_correct))

7   Fail
s = 'One is not enough!'; b = [3 1 1]; y_correct = {'One',' ','i'}; assert(isequal(break_string(s,b),y_correct))

y = 3×1 cell array {0×0 double} {0×0 double} {0×0 double}

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in break_string (line 5) y{i} = s(B(i-1),B(i)); Error in Test7 (line 4) assert(isequal(break_string(s,b),y_correct))

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!