Cody

# Problem 375. N-Dimensional Array Slice

Solution 3852013

Submitted on 26 Nov 2020
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   Fail
A = randn(5,5); assert(isequal(arraySlice(A,4,2),A(:,4)))

A = 1.5745 0.5697 -0.5095 0.1342 -0.2665 -0.0910 -0.2894 0.4817 -0.5357 0.0984 0.9812 0.0323 -0.7711 0.9653 -0.3682 0.3325 -0.8385 -0.1257 0.2865 0.0755 0.7980 0.2780 0.1176 -1.9583 -0.1746

Output argument "ans" (and maybe others) not assigned during call to "arraySlice". Error in Test1 (line 2) assert(isequal(arraySlice(A,4,2),A(:,4)))

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

A = -0.5216 -2.1137 0.8004 -1.2353 0.6408 -0.4059 -1.4977 -0.9617 0.5131 1.2294 1.2194 -0.5221 1.1633 1.1342 2.8776 -1.8535 0.5229 -0.1065 0.7603 -0.4753 -0.2591 0.5472 0.3112 1.5675 -1.7079

Output argument "ans" (and maybe others) not assigned during call to "arraySlice". Error in Test2 (line 2) assert(isequal(arraySlice(A,4,1),A(4,:)))

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

A = -0.9082 2.7284 -0.0697 1.5742 0.7855 1.8336 0.7544 0.0590 0.0399 -0.3199 -0.9261 -0.4795 -0.5913 1.4156 -0.0022 -0.7525 0.4740 -0.6447 0.9704 0.1185 -1.5125 0.2034 0.9198 0.1211 -1.1489

Output argument "ans" (and maybe others) not assigned during call to "arraySlice". Error in Test3 (line 2) assert(isequal(arraySlice(A,1,10),A))

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

A(:,:,1,1) = -0.0052 0.8226 -0.4247 1.7693 -0.2524 1.4046 -0.7747 0.7193 -0.8988 -1.4867 1.3830 -0.5934 0.4863 -2.2230 -0.9088 -0.0360 1.5471 1.1171 1.6314 -0.9874 1.4398 0.6569 -0.7990 -2.5429 0.2083 A(:,:,2,1) = 0.2510 -1.5750 -1.0344 -0.8930 1.1988 -2.2746 -0.3774 -0.4962 1.1783 -1.2530 -1.3870 0.2756 -0.1224 -0.3253 1.3580 0.5289 -1.5516 -0.5888 -1.5280 0.6854 0.4805 0.5522 -2.1369 2.2252 1.4919 A(:,:,3,1) = 1.7759 -0.0533 0.0231 1.1548 -0.0998 0.9355 0.2536 1.5957 -0.3956 -0.3182 0.0636 0.2366 0.1733 -0.2470 0.3281 -0.3174 1.9961 0.6373 -1.4273 1.4558 -0.2737 -0.6476 -0.3589 0.3866 -0.8461 A(:,:,4,1) = 1.6008 -0.8869 0.9414 -0.3742 -1.4472 0.6661 1.0064 1.3844 1.1285 -2.0229 -0.4794 0.0597 1.3466 -0.9857 -0.7262 0.7130 -0.6410 0.0416 1.2034 1.9342 0.4796 -0.9197 0.8318 1.4382 -0.8191 A(:,:,5,1) = 1.6847 0.6415 0.4760 -0.5376 0.1068 0.3446 -0.2186 0.4509 0.1372 0.2552 0.6240 -1.0927 0.1034 -0.2457 1.0893 0.3269 0.2522 -1.8605 0.2680 -0.3947 -0.6034 -1.0887 -0.9636 0.6199 0.1280 A(:,:,1,2) = 0.2868 -0.4151 0.4482 -0.8547 0.4324 -1.7230 -0.1483 -0.1538 1.0569 -0.9342 0.6812 0.1500 -0.3364 0.7092 -0.4266 -1.3212 0.0882 0.0508 -0.4345 -1.7000 -0.2803 -1.0254 0.3952 0.5868 0.2019 A(:,:,2,2) = 0.8628 -2.1776 -0.1123 0.4178 0.0726 1.0794 0.6500 1.3175 -1.0675 0.7850 0.8679 -0.2329 -0.1243 0.1139 -1.7769 1.6957 -1.6301 -0.9733 0.1859 1.5933 -2.1301 0.4756 0.1062 -0.0683 -2.4744 A(:,:,3,2) = -0.5428 -0.8297 0.7977 2.1842 1.1170 -0.3071 -0.3273 1.7119 -2.1556 -0.1710 -0.4708 0.9817 0.9571 -0.5738 -0.8848 -0.7170 1.4324 -0.3537 0.7002 -0.7413 1.3639 0.2049 -0.3278 -1.5687 -0.8788 A(:,:,4,2) = -0.3864 1.4499 -1.5380 -0.2985 -0.6498 -0.0617 -0.5366 0.7489 0.6843 -0.8914 0.6765 -0.0076 1.8124 -0.7404 -0.8518 -0.8508 0.9347 -0.6663 0.6418 -1.4208 1.1971 -0.1001 1.0734 0.2667 -0.2411 A(:,:,5,2) = 1.3020 -0.7622 0.0565 1.0656 0.2826 1.7647 0.2281 0.9951 -0.6704 -0.3180 0.2343 -1.5783 0.3050 0.8261 -0.5334 -2.7466 -0.9180 0.3503 0.8264 -0.0714 -0.1577 -1.9655 -0.0789 0.3366 0.3863 A(:,:,1,3) = 0.9576 -0.7210 -0.3303 -1.1961 0.3173 -1.3347 2.7496 -0.1776 0.9295 -0.3678 1.2423 -0.1037 0.1377 0.7093 1.4148 0.8814 -1.4559 0.3548 0.7145 -1.0963 -1.2527 1.7037 1.2084 -0.8142 -0.0421 A(:,:,2,3) = 2.3102 1.8945 -0.5754 0.7769 -0.4553 -0.1761 -0.2818 0.7799 0.3963 -1.5568 0.8360 0.1677 0.3770 0.6686 -0.1346 1.0266 -0.3803 -1.1432 -1.5059 0.6135 -0.0220 2.0044 0.0434 -1.3202 0.4014 A(:,:,3,3) = 0.1618 0.2219 -1.5821 -1.3484 0.7583 0.5954 0.8085 0.4865 0.2091 -1.7947 0.2599 -0.9266 0.4006 -0.9554 0.9784 0.1723 -0.8945 -0.1230 0.9644 0.2821 0.7016 -0.2720 1.0982 -2.1788 -0.0512 A(:,:,4,3) = 0.9830 -0.7864 1.1746 0.9446 1.6182 -0.3592 0.4948 0.6776 2.2030 -1.0751 2.5589 0.7477 -1.5678 -0.8152 -1.6598 0.8150 1.8076 -0.3067 0.2658 -0.5305 0.9723 -0.9306 0.5886 -0.1638 -0.8064 A(:,:,5,3) = 1.8513 0.8927 0.3956 -1.1308 -0.4919 2.3473 -1.1148 0.0655 1.2230 0.7131 0.8132 0.8436 1.3514 -0.1483 1.9986 0.7224 -0.1797 -0.5756 0.7151 0.9776 1.0000 1.5013 0.1991 0.7346 -0.7491

Output argument "ans" (and maybe others) not assigned during call to "arraySlice". Error in Test4 (line 2) assert(isequal(arraySlice(A,3,4),A(:,:,:,3)))

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

A(:,:,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) = 0.9244 A(:,:,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2) = -0.5552

Output argument "ans" (and maybe others) not assigned during call to "arraySlice". Error in Test5 (line 2) assert(isequal(arraySlice(A,2,18),A(:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,2)))

### Community Treasure Hunt

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

Start Hunting!