Cody

# Problem 3107. Try and Catch Simple Example

Solution 1979859

Submitted on 17 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   Fail
x = [1 4 6 8 10]; n=1; y_correct = 1; assert(isequal(trcatch(x,n),y_correct))

varargin = 1×2 cell array {1×5 double} {[1]}

Unrecognized function or variable 'n'. Error in trcatch (line 3) if n<=0 | n>numel(x) Error in Test1 (line 4) assert(isequal(trcatch(x,n),y_correct))

2   Fail
filetext = fileread('trcatch.m'); assert(~isempty(strfind(filetext, 'try')),'try missing') assert(~isempty(strfind(filetext, 'catch')),'Catch missing')

try missing

3   Fail
x = [1 4 6 8 10]; n=0; y_correct = 0; assert(isequal(trcatch(x,n),y_correct))

varargin = 1×2 cell array {1×5 double} {[0]}

Unrecognized function or variable 'n'. Error in trcatch (line 3) if n<=0 | n>numel(x) Error in Test3 (line 4) assert(isequal(trcatch(x,n),y_correct))

4   Fail
x = [1 4 6 8 10]; n=6; y_correct = 0; assert(isequal(trcatch(x,n),y_correct))

varargin = 1×2 cell array {1×5 double} {[6]}

Unrecognized function or variable 'n'. Error in trcatch (line 3) if n<=0 | n>numel(x) Error in Test4 (line 4) assert(isequal(trcatch(x,n),y_correct))

5   Fail
x = [1 4 6 8 10]; n=5; y_correct = 10; assert(isequal(trcatch(x,n),y_correct))

varargin = 1×2 cell array {1×5 double} {[5]}

Unrecognized function or variable 'n'. Error in trcatch (line 3) if n<=0 | n>numel(x) Error in Test5 (line 4) assert(isequal(trcatch(x,n),y_correct))

6   Fail
x = [1 4 6 8 10]; n=-25; y_correct = 0; assert(isequal(trcatch(x,n),y_correct))

varargin = 1×2 cell array {1×5 double} {[-25]}

Unrecognized function or variable 'n'. Error in trcatch (line 3) if n<=0 | n>numel(x) Error in Test6 (line 4) assert(isequal(trcatch(x,n),y_correct))

7   Fail
x = [1 4 6 8 10]; n=3; y_correct = 6; assert(isequal(trcatch(x,n),y_correct))

varargin = 1×2 cell array {1×5 double} {[3]}

Unrecognized function or variable 'n'. Error in trcatch (line 3) if n<=0 | n>numel(x) Error in Test7 (line 4) assert(isequal(trcatch(x,n),y_correct))