Cody

Problem 42484. Repeat string n times - 2

Solution 2894312

Submitted on 31 Aug 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   Pass
filetext = fileread('rep_str_2.m'); assert(isempty(strfind(filetext, 'for'))) assert(isempty(strfind(filetext, 'while')))

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

Unrecognized function or variable 'x'. Error in rep_str_2>@(i,j)[x,num2str(i),'_',num2str(j)] (line 2) y = arrayfun(@(i,j) [x,num2str(i),'_',num2str(j)], num1:num1+n-1, num2:num2+n-1, 'uni', false)'; Error in rep_str_2 (line 2) y = arrayfun(@(i,j) [x,num2str(i),'_',num2str(j)], num1:num1+n-1, num2:num2+n-1, 'uni', false)'; Error in Test2 (line 9) assert(isequal(rep_str_2(x, num1, num2, n),y_correct))

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

Unrecognized function or variable 'x'. Error in rep_str_2>@(i,j)[x,num2str(i),'_',num2str(j)] (line 2) y = arrayfun(@(i,j) [x,num2str(i),'_',num2str(j)], num1:num1+n-1, num2:num2+n-1, 'uni', false)'; Error in rep_str_2 (line 2) y = arrayfun(@(i,j) [x,num2str(i),'_',num2str(j)], num1:num1+n-1, num2:num2+n-1, 'uni', false)'; Error in Test3 (line 8) assert(isequal(rep_str_2(x, num1, num2, n),y_correct))

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

Unrecognized function or variable 'x'. Error in rep_str_2>@(i,j)[x,num2str(i),'_',num2str(j)] (line 2) y = arrayfun(@(i,j) [x,num2str(i),'_',num2str(j)], num1:num1+n-1, num2:num2+n-1, 'uni', false)'; Error in rep_str_2 (line 2) y = arrayfun(@(i,j) [x,num2str(i),'_',num2str(j)], num1:num1+n-1, num2:num2+n-1, 'uni', false)'; Error in Test4 (line 6) assert(isequal(rep_str_2(x, num1, num2, n),y_correct))

Suggested Problems

More from this Author62

Community Treasure Hunt

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

Start Hunting!