Cody

# Problem 375. N-Dimensional Array Slice

Solution 1997707

Submitted on 31 Oct 2019 by Pooja Lalan
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.2086 0.0871 0.7949 -1.6913 0.2914

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

ans = -1.7028 -0.5183 -0.4304 0.4021 1.3017

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

ans = -0.3972 1.4324 -0.1673 0.7451 1.2100 1.0261 -1.3030 -2.5579 0.5777 -0.9827 -0.2348 0.5358 0.2729 -0.5410 -0.4054 1.0855 0.8773 0.6295 -0.0529 -0.9885 0.9627 -0.1933 -0.4368 -0.2123 -1.7701

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

ans(:,:,1) = -0.2738 0.0909 0.8285 0.3456 1.2431 -0.8512 0.3615 -0.1073 -0.0325 0.5916 -0.1336 1.2310 0.2202 -0.8403 -0.7493 -0.2865 -0.7396 0.2154 -0.3743 0.4137 0.0908 1.1823 -0.3003 1.0288 -0.9698 ans(:,:,2) = 0.1365 1.1109 -0.0070 -2.7618 -1.8249 0.0756 0.5536 -0.0742 0.5048 -0.3327 -0.0954 -1.6178 0.1705 -0.5359 0.8699 0.3935 1.2607 1.7106 0.2512 1.2633 2.0594 1.3687 -1.3022 -0.3309 0.0131 ans(:,:,3) = -1.4344 -0.2828 -0.4895 -0.2727 0.0494 0.2403 0.1919 -2.0370 0.1459 0.6751 0.0098 -1.3571 -0.0340 -0.6659 0.8878 -0.8885 1.0914 -0.9956 -1.5062 0.0633 1.4708 0.0277 0.7386 -0.3552 1.0214 ans(:,:,4) = 0.4729 -1.1656 2.6613 -0.5354 0.2103 -0.3927 -0.5280 0.0984 -0.2849 0.5559 -0.7101 0.4181 1.9074 -0.8315 -1.4879 -0.8513 -0.7354 -1.1581 -1.7107 -1.6285 -0.6331 2.2944 -0.4496 -0.3988 0.3766 ans(:,:,5) = 0.7083 0.0054 1.9950 1.4328 -0.9054 -0.2811 -1.3707 -1.0504 1.0585 -0.0051 -1.6597 0.4085 0.1139 0.0891 0.6918 -1.4919 -1.0567 1.6159 -1.2994 -0.3383 -0.7904 -0.7424 -1.2632 1.2451 0.3223

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

### Community Treasure Hunt

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

Start Hunting!