Cody

# Problem 375. N-Dimensional Array Slice

Solution 1953005

Submitted on 30 Sep 2019 by Eric Mueller
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)))

S = 0.2037 0.8985 -0.1217 1.1979 0.4663

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

S = 0.2879 -0.0041 -0.3558 1.3758 -0.8575

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

S = -0.0558 0.2442 -0.4812 0.3541 -1.5133 -0.1798 0.4192 1.1577 -0.2596 -1.3844 1.3476 1.2637 1.2282 -0.6314 -0.7903 -0.6561 0.8936 -0.0772 -0.6372 0.5039 0.1141 0.4496 1.0769 -1.4976 0.2869

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

S(:,:,1) = -1.0491 -0.2940 -0.5822 0.7348 0.4599 1.4072 -0.4493 -0.3812 1.3443 2.3687 -1.5194 0.1693 0.2199 0.6701 0.2846 0.3628 -1.5786 -0.1016 -0.3633 0.5810 0.2241 1.5357 0.0910 -0.0964 -1.1909 S(:,:,2) = -0.1138 0.5742 0.1044 0.4341 1.4399 1.4737 0.4127 -0.3351 -0.3491 0.0002 0.6312 -0.5093 -0.1410 0.7151 0.1985 -1.5834 0.1972 0.6470 -0.8971 -0.2429 -2.6384 0.8918 0.1357 0.6044 -0.9016 S(:,:,3) = -1.0204 0.1089 -0.2882 -2.1944 -2.8422 0.9317 0.1762 -1.8197 -0.5028 -0.4278 0.4721 -1.2707 -0.6051 -0.5050 0.5610 0.4283 -1.7165 0.4412 0.4654 -0.0034 -1.4288 0.5400 -0.3185 0.1760 -2.1446 S(:,:,4) = -0.9838 -0.8119 -0.4127 -0.0831 -0.4920 -1.0710 0.0474 0.0720 -0.8236 0.3865 -0.8535 -0.6466 0.2830 -1.0861 -0.0582 -0.8728 0.1612 -1.4352 -0.7431 0.0049 1.0454 0.1553 0.4209 -0.0332 2.1835 S(:,:,5) = 0.2938 -0.6509 0.5510 1.5724 0.4105 1.8691 -0.7011 0.5495 -1.3564 -1.7990 1.7461 0.7462 -0.6118 0.3281 -1.0754 -0.8220 -0.3031 -0.2877 1.0438 0.5201 0.2710 -0.9596 0.2962 -1.2241 0.6222

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

### Community Treasure Hunt

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

Start Hunting!