Cody

Problem 375. N-Dimensional Array Slice

Solution 2803522

Submitted on 6 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   Fail
A = randn(5,5); assert(isequal(arraySlice(A,4,2),A(:,4)))

sn = 5 res = []

Assertion failed.

2   Pass
A = randn(5,5); assert(isequal(arraySlice(A,4,1),A(4,:)))

sn = 5

3   Fail
A = randn(5,5); assert(isequal(arraySlice(A,1,10),A))

Index exceeds the number of array elements (2). Error in arraySlice (line 3) sn = [sz(1:d-1) sz(d+1:end)] Error in Test3 (line 2) assert(isequal(arraySlice(A,1,10),A))

4   Fail
A = randn(5,5,5,3); assert(isequal(arraySlice(A,3,4),A(:,:,:,3)))

sn = 5 5 5 res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = []

Assertion failed.

5   Pass
A = randn(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2); assert(isequal(arraySlice(A,2,18),A(:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,2)))

sn = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = [] res = []