Cody

# Problem 375. N-Dimensional Array Slice

Solution 1223257

Submitted on 30 Jun 2017 by Said BOUREZG
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
A = randn(5,5); assert(isequal(arraySlice(A,4,2),A(:,4)))

ans = -0.6375 -0.4606 1.8541 1.1388 -1.1678

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

ans = 1.2527 -0.8617 0.2544 -0.6411 -0.3357

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

ans = -0.4573 0.3661 0.7542 -0.6224 0.3058 0.7948 -0.3854 -0.2685 -0.6422 -1.8788 -2.3392 0.3324 0.5530 -0.8683 1.2607 0.0681 -1.0193 0.4664 0.4953 1.8998 -0.3820 1.1589 -0.6628 2.1647 1.3604

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

ans(:,:,1) = -0.7450 2.2940 -0.7466 -1.0104 -0.8539 0.4144 -0.1580 -1.9721 -1.6635 -1.5594 -0.2739 2.1955 0.5838 1.1867 1.2280 0.2304 -0.0457 -0.4073 -0.4660 -0.1357 -0.2550 -1.2654 -0.9710 -0.3569 0.6057 ans(:,:,2) = -0.0743 -1.1063 1.8976 2.0744 1.4078 -2.8033 0.9608 -1.0296 0.5606 0.9118 0.5935 2.0416 1.1962 1.2879 -0.9914 -0.2186 1.4122 -0.5770 0.4631 1.2394 1.1419 -0.6568 0.0578 0.0760 0.4184 ans(:,:,3) = -0.8365 -0.2181 -0.7548 0.1887 -0.1228 -2.8702 -0.6894 0.1774 -0.4018 -0.4362 0.6960 -0.1576 -1.1219 0.1230 0.6906 0.0203 0.8133 0.6298 -0.1923 -0.2203 -2.0254 -0.6040 -1.0354 -0.2617 0.3882 ans(:,:,4) = 0.1715 1.1084 -0.0268 -0.5248 -1.1369 -0.9033 -1.3086 -0.7095 0.8696 0.7363 -0.3145 -0.0280 0.4648 1.2467 2.3596 -0.2469 0.5388 0.6113 -0.5506 -0.8916 0.4050 -0.0318 0.3022 -1.7924 -1.5239 ans(:,:,5) = -0.2374 1.2450 -1.9988 3.1506 -0.0412 0.2349 -0.7948 1.6843 -0.7005 0.1831 -0.8074 0.6590 1.1952 -0.7617 -0.3601 1.0442 -0.1202 -0.8997 -0.5815 0.1670 -0.3449 0.7749 -0.8678 -0.3541 0.8178

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

ans = -0.0087