Cody

Problem 375. N-Dimensional Array Slice

Solution 3174261

Submitted on 12 Oct 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)))

Index in position 2 exceeds array bounds (must not exceed 2). Error in arraySlice (line 6) S = A(ind(1,1):ind(2,1),ind(1,2):ind(2,2),ind(1,3):ind(2,3),ind(1,4):ind(2,4),ind(1,5):ind(2,5),... Error in Test1 (line 2) assert(isequal(arraySlice(A,4,2),A(:,4)))

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

Index in position 2 exceeds array bounds (must not exceed 2). Error in arraySlice (line 6) S = A(ind(1,1):ind(2,1),ind(1,2):ind(2,2),ind(1,3):ind(2,3),ind(1,4):ind(2,4),ind(1,5):ind(2,5),... Error in Test2 (line 2) assert(isequal(arraySlice(A,4,1),A(4,:)))

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

Index in position 2 exceeds array bounds (must not exceed 10). Error in arraySlice (line 8) ind(1,11):ind(2,11),ind(1,12):ind(2,12),ind(1,13):ind(2,13),ind(1,14):ind(2,14),ind(1,15):ind(2,15),... 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)))

Index in position 2 exceeds array bounds (must not exceed 4). Error in arraySlice (line 6) S = A(ind(1,1):ind(2,1),ind(1,2):ind(2,2),ind(1,3):ind(2,3),ind(1,4):ind(2,4),ind(1,5):ind(2,5),... Error in Test4 (line 2) assert(isequal(arraySlice(A,3,4),A(:,:,:,3)))

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

Index in position 2 exceeds array bounds (must not exceed 18). Error in arraySlice (line 9) ind(1,16):ind(2,16),ind(1,17):ind(2,17),ind(1,18):ind(2,18),ind(1,19):ind(2,19),ind(1,20):ind(2,20)); Error in Test5 (line 2) assert(isequal(arraySlice(A,2,18),A(:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,2)))

Suggested Problems

More from this Author56

Community Treasure Hunt

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

Start Hunting!