Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Correct

16Size
This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, log in.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
M(:,:,1) = [1 2 3; 4 5 6];
M(:,:,2) = [10 20 30; 40 50 60];
Element = 50;
y_correct = 10;
assert(isequal(FindOffset(M, Element),y_correct))

                    
2
Pass
 
%%
M(:,:,1) = [1 2 3; 4 5 6];
M(:,:,2) = [10 20 30; 40 50 60];
M(:,:,3) = [100 200 300; 400 500 600];
Element = 6;
y_correct = 6;
assert(isequal(FindOffset(M, Element),y_correct))

                    
3
Pass
 
%%
M(:,:,1) = [1 0 0; 0 1 0]
M(:,:,2) = [1 0 1; 1 1 0]
M(:,:,3) = [1 1 1; 0 0 0]
Element = 0;
y_correct = 2;
assert(isequal(FindOffset(M, Element),y_correct))
M =
     1     0     0
     0     1     0
M(:,:,1) =
     1     0     0
     0     1     0
M(:,:,2) =
     1     0     1
     1     1     0
M(:,:,1) =
     1     0     0
     0     1     0
M(:,:,2) =
     1     0     1
     1     1     0
M(:,:,3) =
     1     1     1
     0     0     0
4
Pass
 
%%
M(:,:,1,1) = [10 20 350; 30 1 50]
M(:,:,2,1) = [12 0 11; 13 15 60]
M(:,:,1,2) = [4 5 6; 70 80 100]
M(:,:,2,2) = [1000 2000 3000; 4000 5000 6000]
Element = 70;
y_correct = 14;
assert(isequal(FindOffset(M, Element),y_correct))
M =
    10    20   350
    30     1    50
M(:,:,1) =
    10    20   350
    30     1    50
M(:,:,2) =
    12     0    11
    13    15    60
M(:,:,1,1) =
    10    20   350
    30     1    50
M(:,:,2,1) =
    12     0    11
    13    15    60
M(:,:,1,2) =
     4     5     6
    70    80   100
M(:,:,2,2) =
     0     0     0
     0     0     0
M(:,:,1,1) =
    10    20   350
    30     1    50
M(:,:,2,1) =
    12     0    11
    13    15    60
M(:,:,1,2) =
     4     5     6
    70    80   100
M(:,:,2,2) =
        1000        2000        3000
        4000        5000        6000
5
Pass
 
%%
M(:,:,1) = [1 20 30; 40 5 60]
M(:,:,2) = [89 90 100; 101 135 99]
M(:,:,3) = [6 19 67; 31 41 45]
Element = 102;
y_correct = 0;
assert(isequal(FindOffset(M, Element),y_correct))
M =
     1    20    30
    40     5    60
M(:,:,1) =
     1    20    30
    40     5    60
M(:,:,2) =
    89    90   100
   101   135    99
M(:,:,1) =
     1    20    30
    40     5    60
M(:,:,2) =
    89    90   100
   101   135    99
M(:,:,3) =
     6    19    67
    31    41    45