Cody

Solution 669776

Submitted on 13 May 2015 by James
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)))

A = 0.6008 -1.3803 -0.8849 -0.7177 -0.4690 -1.2359 -1.3706 0.2152 1.3398 -0.7411 -1.0019 -0.3036 -0.5419 -0.3623 -0.3359 -1.1966 0.7431 -0.1462 -0.5447 -0.3870 2.0951 0.9977 0.6152 0.1251 0.6524

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

A = -0.0946 0.1679 1.1861 1.0150 0.6408 -0.5540 0.2222 -0.0125 0.3673 -2.3192 0.6634 -0.3575 0.1513 0.5274 -0.0472 0.1223 -0.7870 -1.1012 -1.6308 1.1286 0.3358 -2.1447 0.3816 -0.3041 -0.0073

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

A = 0.3330 0.3567 -2.2834 0.7657 0.3062 1.2325 0.6061 -1.4276 -0.6260 -0.0234 0.3940 1.1481 0.5642 1.0096 -0.4569 0.4019 0.8655 -0.2063 -1.9134 -1.5701 -0.4852 0.5140 0.1760 0.7521 -0.3207

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

A(:,:,1,1) = -0.5816 0.4310 1.4679 -1.9763 0.1644 0.5425 1.4080 -0.3491 -0.6275 -0.9836 1.7896 0.2650 -0.3223 -0.5070 0.2471 0.1592 0.4589 -0.5138 -0.2841 -1.1239 -0.3930 0.9540 -1.0464 -0.0877 -0.4997 A(:,:,2,1) = 0.7688 -0.0455 1.1014 -0.6503 -1.5838 1.0421 0.2227 -0.5339 0.4647 0.6398 0.2057 -1.2296 1.2080 0.0459 2.9674 0.2235 1.2515 -1.3086 -2.2929 -0.2373 -1.3849 -0.9130 0.6552 0.1896 -0.3717 A(:,:,3,1) = 0.0206 0.4859 -0.0887 0.2750 0.1022 -0.1050 -0.8702 0.2580 -1.3256 -0.7176 0.9999 -1.4457 -0.1319 -0.1385 1.3092 -1.4737 1.1943 0.6424 -0.0616 0.8467 -1.3618 -0.3923 -1.7556 0.6102 -0.6948 A(:,:,4,1) = 0.9671 1.0507 0.6169 0.6562 -0.6337 -0.9453 -1.4018 0.2575 0.5125 0.5516 -0.7300 1.0089 0.7581 0.3116 -0.2435 0.4565 -0.8102 -1.6292 -2.1646 0.3304 0.9449 0.2099 0.6710 1.6608 0.5947 A(:,:,5,1) = 2.6536 -0.6201 1.1330 -0.0581 0.7340 -0.0573 0.6615 -0.0416 -0.3238 0.1836 -0.8854 -0.3332 -1.4623 0.6565 0.0391 -0.5961 -0.3028 1.1110 -2.0446 2.1620 0.1524 1.4544 -0.4260 -0.3909 -0.7561 A(:,:,1,2) = 0.8152 -1.2646 0.8712 -1.3378 0.1586 1.1185 -1.0698 0.9351 -1.8707 0.4402 0.5003 1.1813 -1.3062 0.5769 0.2259 0.1393 0.6772 -0.4707 0.2729 0.0753 0.4925 -0.8850 -0.3603 0.5412 -1.2216 A(:,:,2,2) = -0.7212 -1.3470 -0.4511 0.6419 -0.3073 0.5818 0.8537 -0.5484 1.6838 0.1169 0.0613 -0.6089 -0.4433 -0.5040 -1.2203 0.5183 -0.9294 -0.4500 1.0922 -0.3641 -1.3490 -1.4295 -0.0353 -1.5251 -1.5602 A(:,:,3,2) = 0.2422 0.8911 1.2301 -0.0195 -1.1851 1.0934 -0.2703 -0.5624 -0.2587 2.0846 -0.5040 0.0027 0.1744 0.9020 -1.8220 2.4744 -0.2552 -0.2557 1.7204 0.3506 -1.5658 -0.0413 1.1959 -2.2249 0.8941 A(:,:,4,2) = 1.1306 0.9896 -2.2144 0.2120 0.8034 -1.7615 0.2263 0.2386 -0.3014 -0.6558 -0.8598 -1.5552 0.0541 -1.4059 0.5832 1.0758 -1.0513 0.7639 -2.5464 -1.1033 -1.3555 -1.0447 -0.6724 2.1573 -1.1159 A(:,:,5,2) = 0.2234 -0.4238 1.8276 3.0435 0.6077 1.5780 1.7758 0.3282 -0.9677 0.5553 -1.3668 -2.0538 1.2263 -1.3105 -2.4426 -0.5924 0.7439 0.5748 0.6579 -0.1485 0.1011 -1.1280 -0.2771 -0.3079 0.4251 A(:,:,1,3) = -0.5492 -0.8856 0.5178 0.6644 -0.3234 1.3279 1.2693 0.8110 -0.5325 -0.6190 -0.6246 -0.3819 0.1807 -0.8413 0.1955 0.9595 -0.2148 -0.1092 -0.3006 -0.3547 0.1129 -0.4967 -0.4985 -0.3554 -1.7884 A(:,:,2,3) = 1.8705 1.0550 0.4430 -0.2747 -0.1273 0.5423 -0.0866 0.1668 1.5506 0.3492 0.2576 -0.3852 -0.6604 -1.4889 -0.0172 -0.2872 -0.0340 0.0861 -0.5508 -0.8395 0.4660 -0.3525 -0.2603 -0.1170 1.7132 A(:,:,3,3) = -0.4338 -1.3187 0.9936 -2.8299 1.2222 -0.0268 -0.4430 -0.9649 0.5077 -1.3603 0.8651 1.4962 -0.3604 -1.2516 -0.6738 0.7571 -1.4195 0.4659 -0.5996 -1.4026 1.5235 -0.7513 1.4746 -0.0060 0.1097 A(:,:,4,3) = 1.0143 -0.3102 -0.8458 0.5839 -0.0225 0.8120 0.1434 -0.6534 0.2398 0.8544 -2.2032 -2.3420 0.4241 -0.6857 0.8374 -0.4549 0.8733 0.9277 -1.9273 -1.0218 -0.5240 2.3435 -1.1648 -0.6207 1.6304 A(:,:,5,3) = -0.7002 -0.9057 0.1385 -0.6867 -0.5340 -0.1954 -2.0161 0.3996 -1.0029 0.3642 -0.4228 1.0973 -1.2522 1.2821 0.0894 1.1419 0.4002 -0.4165 0.8040 1.6133 0.2554 0.4358 -1.3530 0.3536 -0.4912

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

A(:,:,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) = -0.8578 A(:,:,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2) = -0.3192