Cody

Solution 1805025

Submitted on 4 May 2019 by Ed P.
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)))

indices = 1×2 cell array {':'} {[4]} S = -0.1410 0.5655 -0.7213 0.9266 0.1880

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

indices = 1×2 cell array {[4]} {':'} S = -0.6753 -2.1156 0.7132 0.9995 -1.0888

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

indices = 1×10 cell array {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {[1]} S = 0.6960 0.7537 0.2371 -0.2476 0.2622 0.0723 0.4623 -0.5308 0.8952 -0.2690 -0.6686 0.0863 0.3456 0.4181 -1.6475 -0.2995 0.5870 -1.6032 0.1296 -0.0215 -1.4506 0.0130 0.3820 0.1175 -1.7064

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

indices = 1×4 cell array {':'} {':'} {':'} {[3]} S(:,:,1) = -1.4930 0.7311 0.0376 0.1862 1.1966 0.5553 0.4642 0.2250 0.2355 1.2055 -0.0606 1.3665 -0.1682 2.3946 -1.7035 0.0623 0.1950 -0.6020 1.1362 -1.0529 0.4508 1.0114 0.2983 -0.8472 -2.4135 S(:,:,2) = 1.1176 1.1791 0.7154 -0.1766 -1.1320 1.0439 0.6072 1.1954 -1.9887 0.2088 0.7028 0.6210 -0.7854 -2.3875 -0.5453 0.0258 -0.0963 0.6679 -2.5749 -1.3369 0.2625 -0.0920 -0.1919 0.1255 0.3238 S(:,:,3) = 0.1866 1.9937 -0.3098 1.2185 0.2105 0.5262 -1.1865 1.4302 0.3186 0.1832 -0.4220 0.1724 0.1830 0.1959 0.2620 -1.0143 -0.2689 0.0398 1.2605 0.5523 0.6673 0.5604 0.5212 0.1628 -1.5424 S(:,:,4) = 0.0633 1.0589 0.2074 -1.6852 0.1560 -0.0574 0.7510 0.8276 0.8258 -0.1532 0.4089 0.1640 -0.3991 0.9884 1.2745 0.0538 -0.3349 -0.8069 1.2242 -0.4296 -1.3158 1.0728 -0.0773 -1.8488 0.2496 S(:,:,5) = 1.0178 -0.7934 -0.1541 -0.2751 0.4434 0.1952 -1.5964 0.2208 -0.8060 -0.4986 0.1948 -1.9943 1.1418 -2.0548 0.4795 -0.1816 0.9087 0.6459 0.1061 -0.6611 -0.1963 -0.1875 -0.4660 -0.1315 -1.5054

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

indices = 1×18 cell array {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {':'} {[2]} S = -0.4002

Suggested Problems

More from this Author57