Cody

# Problem 375. N-Dimensional Array Slice

Solution 2954911

Submitted on 16 Sep 2020 by Reshma Meah
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.1303 -0.7825 2.5494 -0.8549 1.3257

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

S = -0.5081 -0.0680 -1.3084 0.4514 -0.1099

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

S = 0.2588 -1.9755 0.8038 0.4384 -0.4728 0.4987 -0.1274 0.3104 -0.1930 -0.3077 1.4549 0.9118 0.5984 -0.5502 -1.6362 0.4870 0.5375 -0.3595 -1.1079 0.6875 -1.4713 2.2605 -0.1010 1.0489 -1.3379

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

S(:,:,1) = 0.0515 1.2663 -1.2061 0.0269 0.8932 0.4213 -0.3638 1.3985 0.5341 0.0664 -1.4935 0.3195 -0.4898 0.4584 -0.6226 -0.2623 -1.1270 0.2228 1.0268 1.1438 -1.1456 -1.3673 0.0366 -1.6960 -1.5698 S(:,:,2) = -0.2579 -0.2684 -2.0731 0.2036 1.8306 0.8304 2.0568 0.6203 -0.2311 0.1980 -0.0096 0.4186 2.1939 0.2953 1.0971 0.3913 0.8202 -2.7299 -0.1726 0.7347 0.7833 -1.2380 0.4251 -0.8915 0.0428 S(:,:,3) = 0.8666 0.8538 1.5363 -1.1464 2.0383 -0.5402 -0.6684 2.5339 -1.5176 0.0295 -0.5166 -0.3205 0.7264 1.0136 0.4497 1.8805 -0.0226 -0.1410 -2.1885 0.4174 -0.9820 -0.8999 -0.1072 0.1610 0.4819 S(:,:,4) = -0.0589 0.6010 -0.8427 -0.3010 -0.4902 -0.4988 0.9219 1.4668 0.2534 0.7002 -0.3144 0.3585 0.0031 -2.0418 0.8418 1.6377 -0.0371 0.5492 -0.0341 -0.3123 -0.5864 -1.8731 -0.3542 -0.5482 -0.4375 S(:,:,5) = -0.8364 0.4151 0.9076 0.5383 -0.8621 0.6230 -1.1473 -0.6740 -1.6218 1.2847 -0.5267 0.5758 2.1539 0.2947 -1.7291 2.2282 0.4871 -0.4124 0.2063 0.3427 -0.1316 1.5042 1.3771 -1.0538 -1.6343

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

S = -0.1896

### Community Treasure Hunt

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

Start Hunting!