Cody

# Problem 375. N-Dimensional Array Slice

Solution 2104221

Submitted on 24 Jan 2020 by xr hu
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.8794 -0.5472 0.3608 1.5669 -1.3253

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

ans = 0.9088 -0.3268 0.6749 0.5577 0.2932

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

ans = 1.2245 0.7079 -0.6072 -0.5321 -0.0128 -0.3407 1.1082 0.7898 -0.6087 0.3309 0.9052 -0.1913 -0.5850 -1.0166 1.8690 -1.1800 -0.7417 -0.3210 -1.4640 0.3348 0.8669 -0.3069 0.4307 -1.0317 -1.8541

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

ans(:,:,1) = 1.3776 0.3269 0.1865 -1.5185 0.4969 -0.9187 -0.8413 0.0007 1.0763 0.1852 0.2682 0.8384 -0.5766 0.8200 -1.0207 0.4196 0.7165 0.3431 0.8825 0.3601 -0.2764 -0.4016 -1.4329 -0.5589 0.3875 ans(:,:,2) = -0.3843 1.2755 0.8327 -1.1593 -0.6618 2.9747 1.5220 -1.6726 -0.5853 1.2651 -0.7532 -0.6702 -2.1101 1.6997 0.3717 -2.5386 -1.1187 1.4910 -1.1466 -0.0423 0.7473 -2.2614 0.1918 -0.8723 -0.6162 ans(:,:,3) = -0.5081 0.0933 0.9456 0.0535 -0.1063 -2.0082 -0.7369 1.5400 -0.6813 0.6542 -0.8792 0.3180 0.6873 0.9096 -0.3792 -0.8031 0.2764 -0.2845 -0.1025 -0.2134 -1.4234 -0.5263 0.0555 -1.5198 2.1176 ans(:,:,4) = 0.8518 -0.1221 0.0272 -0.8580 0.7290 1.1154 1.0677 0.3627 -1.9048 -1.2570 0.3216 1.7534 0.0816 -0.4371 -0.3398 0.3548 0.4253 0.6978 0.1274 -0.8007 0.7715 1.0358 0.1030 -0.7271 -0.0227 ans(:,:,5) = 0.8700 0.5435 0.3052 0.5235 -0.5124 1.6536 2.0463 0.0611 0.4234 0.2241 1.8460 0.5150 0.0406 0.1653 -1.1055 0.4568 0.9339 -0.2523 -2.2820 0.5236 0.9794 1.6962 1.3870 0.9561 -2.2104

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