Cody

# Problem 375. N-Dimensional Array Slice

Solution 3062065

Submitted on 4 Oct 2020 by Mayank Bajpai
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)))

dim = 5 1 S = 0.6288 1.5049 0.2447 0.2732 1.5529

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

dim = 1 5 S = 1.4178 -0.6537 -0.3475 -0.7855 0.6441

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

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

dim = 5 5 5 1 S(:,:,1) = -1.3831 0.1007 -1.1678 -1.1815 0.2433 1.2201 1.1888 -1.2801 -0.4569 0.4294 -1.0680 -0.6288 0.1569 -0.3665 -0.9437 -0.1961 -0.8016 0.1121 1.0410 0.1377 1.3351 0.6563 -0.5451 0.1841 0.4847 S(:,:,2) = -2.7731 1.2167 0.3446 0.9621 -1.3077 1.1266 -0.3145 -0.2146 0.7931 -0.0513 0.0855 -1.5768 -1.2549 -2.0437 1.1852 -1.6648 1.2442 -0.2911 1.2797 -0.4016 0.1728 -1.2625 1.3964 0.1493 -0.8742 S(:,:,3) = 1.9481 -1.1002 0.4714 -0.7301 0.0088 -0.0151 0.2102 1.3101 -1.2449 0.0881 1.5696 -0.2274 1.6718 -0.4670 1.7141 -1.0726 -1.1935 0.6981 -0.6687 0.5103 0.1251 -0.2067 0.3768 0.1521 -0.3301 S(:,:,4) = 0.1206 0.7451 -0.5231 -0.7803 -0.4873 -0.6062 0.0736 0.3067 0.3313 1.4264 -0.2936 0.8487 -1.1499 0.7394 -0.6062 0.9358 -1.4215 -0.9042 -0.1677 -2.3613 -1.7087 -1.0195 0.8567 -0.6328 -0.9312 S(:,:,5) = -1.0893 0.1266 0.2788 0.9613 0.6928 0.5494 -2.8546 -0.5511 0.5520 -1.1162 1.2372 1.4574 1.2940 -0.2303 -0.3722 0.2176 -0.5346 -1.2756 0.6715 -0.2296 0.0705 0.6752 0.3337 0.3506 0.6211

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

dim = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 S = 0.6397

### Community Treasure Hunt

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

Start Hunting!