Cody

Problem 2121. Find offset of given matrix element from first matrix element

Solution 2574303

Submitted on 17 Jun 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
m=[11 2 34; 40 51 6; 87 8 109] element = 51; offset = 5; assert(isequal(FindOffset(m,element),offset));

m = 11 2 34 40 51 6 87 8 109 ans = 5

2   Pass
m=reshape([1:10],5,2); element = 9; offset = 9; assert(isequal(FindOffset(m,element),offset));

ans = 9

3   Pass
m=eye(7); element = 0; offset = 2; assert(isequal(FindOffset(m,element),offset));

ans = 2

4   Fail
m=[10 20 30 40; 50 60 70 80;]; element = 56; offset = 0; assert(isequal(FindOffset(m,element),offset));

Index exceeds the number of array elements (0). Error in FindOffset (line 3) a(1) Error in Test4 (line 4) assert(isequal(FindOffset(m,element),offset));