Cody

Problem 375. N-Dimensional Array Slice

Solution 483503

Submitted on 6 Aug 2014 by rifat
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.9204 -0.0911 -0.0566 -1.1339 -0.2432

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

ans = 1.1780 0.5455 1.2934 0.6682 -1.0854

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

ans = -0.9854 -1.7966 -1.8333 0.8914 -0.3387 -0.5604 0.8848 0.1144 0.3727 0.4238 0.0842 1.7184 -0.2195 0.0619 0.5758 -0.9272 1.3160 -0.9112 1.4702 0.6163 1.1720 0.1930 0.4734 1.2931 -0.3552

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

ans(:,:,1) = -0.1618 0.7736 0.7226 0.2971 0.5704 -1.5611 2.0472 0.1604 0.4344 1.5004 -0.2876 -0.4829 -1.0943 0.8280 0.4643 -0.1233 -1.8027 1.4270 0.6926 -0.3066 -0.7635 0.8383 0.9712 -0.4818 0.5777 ans(:,:,2) = 1.3370 -0.4986 -0.8442 0.3442 -2.1200 0.9917 0.9413 -0.8931 0.9154 -1.0857 0.9251 0.8102 1.0355 -0.6716 -0.3700 1.2186 -1.4883 -0.0961 -0.8258 -0.1107 -0.0075 -0.2163 2.3131 -0.6749 0.0303 ans(:,:,3) = -0.4654 -0.4818 0.5927 1.1356 0.5103 1.0633 -0.5845 -0.3116 0.0793 -1.7275 1.4468 -1.4910 -1.6616 -0.4658 -0.7062 1.2163 -1.1622 1.0199 -0.0315 0.3383 -0.4731 0.9565 -0.3876 -0.5960 1.3331 ans(:,:,4) = -0.0347 0.5417 1.2537 -0.2201 0.6516 -0.2591 -1.1314 0.4486 0.3388 -1.3627 -1.4758 -1.7635 -0.2206 -0.4854 0.0968 -1.4057 -1.1796 0.7839 -1.8144 -0.1432 1.9068 -0.4668 0.5245 0.2224 -2.8782 ans(:,:,5) = -0.3203 -0.6049 -1.0686 -0.7912 -0.1750 -0.7169 -1.4974 1.2184 -0.5490 0.3237 0.9244 1.5011 -0.1512 -0.1722 0.0404 -1.8736 -1.8568 -0.8614 -0.0521 -0.4218 -0.4955 -1.6487 1.5868 -0.2409 -0.8119

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

ans = 0.2707