Cody

Solution 1837273

Submitted on 4 Jun 2019 by John Walker
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×5 cell array {5×1 double} {5×1 double} {5×1 double} {5×1 double} {5×1 double} ans = 1.2658 -0.6530 -0.3920 -0.3207 -1.3080

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

ans = 5×1 cell array {1×5 double} {1×5 double} {1×5 double} {1×5 double} {1×5 double} ans = -1.7811 1.4269 -0.9885 1.1818 0.6380

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

ans = 1×1 cell array {5×5 double} ans = -0.8618 -1.0728 -1.1152 1.8307 -1.0848 -0.6664 1.6285 -1.8595 0.6680 1.2551 -1.3801 0.1679 0.9028 -0.6945 0.6758 -0.4235 0.8078 -0.9854 -1.3670 0.4735 0.3964 -1.3267 -0.1117 1.3557 -0.4773

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

1×1×1×3 cell array ans(:,:,1,1) = {5×5×5 double} ans(:,:,1,2) = {5×5×5 double} ans(:,:,1,3) = {5×5×5 double} ans(:,:,1) = -1.0580 -1.3687 1.1137 -0.0167 1.2887 -0.3707 1.3032 -0.4911 2.4453 0.2735 0.0042 -0.4999 0.1420 1.5057 -0.4054 1.7712 -1.3450 -0.9824 -1.0020 1.1151 1.0991 0.2835 1.2497 1.4728 0.4394 ans(:,:,2) = 0.0718 -1.0396 0.5138 1.5521 -0.4410 1.5131 -0.9107 0.6314 -1.9306 -0.0211 -0.1398 0.9980 2.5431 0.5110 -0.7229 0.3929 -0.9839 0.0657 -1.9944 -0.2938 0.0050 -0.6883 -1.2668 -0.4155 -2.0278 ans(:,:,3) = 0.5143 -0.2664 -1.7937 2.0848 -0.8936 -1.1796 0.4958 0.5157 -0.1360 0.7215 0.2303 -0.3883 -0.3074 -0.1695 0.4913 -2.0659 -0.8916 0.7760 0.4943 -0.1960 1.2423 -0.6705 -0.3002 -0.4307 0.3521 ans(:,:,4) = -0.5529 0.9325 -0.6133 0.6545 0.6216 0.0678 -0.3611 -0.8319 -1.0090 0.1711 0.3914 -0.0660 -1.8692 -0.3203 0.2318 0.8464 0.2610 0.5676 -2.4590 1.5501 0.4536 -1.1651 -2.5135 0.9785 0.8185 ans(:,:,5) = -1.0014 -0.1453 -1.1283 0.6087 -0.1721 0.6960 -0.3867 0.7224 1.3635 -1.4658 0.1533 -1.2929 -1.4548 0.4175 -0.0084 -0.9450 -0.7003 -1.2010 0.0764 0.9057 -0.1160 0.6633 0.8059 -0.4360 -0.3635

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

18-D cell array ans(:,:,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) = {[-0.6574]} ans(:,:,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2) = {[-1.4403]} ans = -1.4403