Cody

# Problem 375. N-Dimensional Array Slice

Solution 2064757

Submitted on 20 Dec 2019 by Gareth Lee
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 = -1.4127 -0.3853 -0.7825 -0.2844 1.1851

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

ans = 0.0192 -1.2194 2.2674 1.6675 2.0303

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

ans = 0.9798 0.4996 0.5513 0.0548 -0.0081 -2.6063 1.0580 -0.8428 0.9272 0.0052 0.8648 0.1645 2.3541 -0.4271 1.3170 -0.6212 1.2175 -0.3737 -0.4805 0.2225 -0.7398 1.4861 1.4532 -0.1414 -0.5796

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

ans(:,:,1) = -0.5456 0.7301 -0.1577 -0.5084 -0.4034 0.1941 0.1873 -0.0338 -0.5141 0.9023 0.5293 -0.5617 0.1313 1.1328 1.2756 -0.0932 -0.5334 -0.5292 -0.6338 -0.1336 -0.5368 0.0432 1.1866 2.0896 1.2531 ans(:,:,2) = 2.9150 1.4348 1.4162 -0.2095 0.9580 0.0726 1.5720 -1.1932 0.4202 0.8548 1.8905 0.2825 0.0457 0.5267 1.8770 -0.7431 -0.1176 -1.4058 0.9481 1.0393 0.0962 0.5602 -1.6013 0.0553 1.0013 ans(:,:,3) = 0.2164 0.2873 0.2786 -0.6049 -1.1228 0.0373 -0.3368 -0.4025 0.6636 -0.1541 -1.3085 0.9014 -1.9590 2.6620 0.0343 0.1099 0.0221 0.4874 0.0872 0.7811 0.4324 1.2504 0.3684 0.9324 1.4763 ans(:,:,4) = 0.3567 -0.0071 -1.5412 0.6231 -1.2513 -1.2611 -1.5073 0.3926 0.3648 -0.3046 -0.1166 -1.9912 0.2712 -0.5573 -1.9693 1.0047 0.7293 1.0304 0.1546 0.2341 0.0853 0.7244 0.3725 1.2107 -0.4498 ans(:,:,5) = 0.0051 2.2599 0.8949 0.0460 0.1459 -0.1083 1.7659 2.5612 -1.9689 -0.0853 -0.3226 -0.0214 -0.8347 2.3088 0.1736 0.1414 -0.5722 -1.1996 -1.5248 -0.5293 0.8590 -0.3519 0.3174 0.4187 -0.1432

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.4350