Cody

Solution 1997680

Submitted on 31 Oct 2019 by Pooja Lalan
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 = 1 4 S = -0.6101 -0.1676 -1.0990 -0.0497 -0.0354

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

a = 4 1 S = 0.5991 -1.2739 -1.4434 0.7682 -0.4751

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

S = 1.4295 -1.1015 -0.0486 -1.6722 -1.1913 -0.6099 -0.6272 0.3842 -0.5554 1.1013 -0.7543 -0.6200 1.2098 -0.6952 -0.1607 -0.7406 -0.4115 1.1086 0.6153 -1.0878 0.4915 -1.2354 1.5955 -2.4898 2.1934

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

a = 1 1 1 3 S(:,:,1) = -0.0421 0.5329 1.5711 -1.5546 -1.0466 1.3005 0.1372 -0.3299 -0.6657 -0.0252 -0.6995 -1.3059 -0.0262 1.2350 -0.9142 1.8117 0.5635 0.6376 2.0575 -0.7949 1.3535 -0.4548 0.6928 -0.0925 -0.4516 S(:,:,2) = 0.5120 1.4143 0.2231 -0.6031 -0.9656 -0.0234 0.3536 -0.3061 -1.1801 -0.4883 -1.0330 0.7752 -2.5507 -1.8484 -0.1385 0.7488 1.2665 1.6724 -0.3526 1.0240 -1.5492 0.0897 -0.5215 -1.6186 0.0313 S(:,:,3) = 0.2865 -1.1214 0.7475 0.1398 -1.1619 0.1675 1.3376 -1.6661 0.2771 0.6265 -0.2077 -0.3807 -0.2054 -0.9741 2.0287 -1.0049 2.6171 2.3031 -0.1750 0.6166 -0.5424 -1.4986 -1.7462 -0.0636 0.8254 S(:,:,4) = 0.4210 0.4189 0.8547 -0.1909 -0.0414 0.1900 0.2782 1.4853 -0.0872 -0.7521 -1.0338 0.6403 -0.4569 -1.0531 0.8747 1.6880 0.7511 -0.8721 0.6178 -0.0706 0.3712 -1.0990 0.6889 0.6623 -1.8539 S(:,:,5) = 1.3098 0.7548 0.5121 0.3418 -0.5039 1.0103 0.9358 0.2460 0.3792 -0.4587 -1.0330 -0.4800 0.5646 -0.1286 0.1205 -0.0686 -0.9712 -0.6165 -0.4789 0.0271 1.3754 -1.0575 0.6982 0.9874 0.6365

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 1 2 S = -1.9524