Cody

# Problem 1896. Index one element in each vector of an array along a given dimension

Solution 2242339

Submitted on 28 Apr 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
for a = 1:30 ndms = ceil(rand(1) * 5) + 1 sz = 1 + ceil(rand(1, ndms) * 10); A = rand(sz); sz1 = sz(1); sz(1) = 1; I = ceil(rand(sz) * sz1); B = reshape(A(I(:)+(0:sz1:numel(A)-1)'), size(I)); p = randperm(ndms); A = permute(A, p); I = permute(I, p); B = permute(B, p); assert(isequal(dimsel(A, I), B)); end

ndms = 6 s = 6 pp = 2 1 3 4 5 6 aa(:,:,1,1,1,1) = 0.8110 0.5564 0.3203 0.5691 aa(:,:,2,1,1,1) = 0.5029 0.7896 0.5214 0.6592 aa(:,:,3,1,1,1) = 0.4611 0.0327 0.3170 0.9213 aa(:,:,4,1,1,1) = 0.7807 0.4435 0.0976 0.9996 aa(:,:,5,1,1,1) = 0.0063 0.7501 0.2197 0.7287 aa(:,:,6,1,1,1) = 0.0974 0.6247 0.2269 0.0429 aa(:,:,7,1,1,1) = 0.2890 0.0375 0.7577 0.6017 aa(:,:,1,2,1,1) = 0.5997 0.9184 0.1317 0.0828 aa(:,:,2,2,1,1) = 0.5613 0.2813 0.1624 0.7419 aa(:,:,3,2,1,1) = 0.8928 0.3446 0.9891 0.6592 aa(:,:,4,2,1,1) = 0.3159 0.5661 0.6766 0.4538 aa(:,:,5,2,1,1) = 0.9406 0.4925 0.7549 0.5951 aa(:,:,6,2,1,1) = 0.4573 0.3239 0.7478 0.8724 aa(:,:,7,2,1,1) = 0.2508 0.2344 0.0843 0.3396 aa(:,:,1,3,1,1) = 0.0090 0.6420 0.8900 0.5670 aa(:,:,2,3,1,1) = 0.8963 0.3993 0.9378 0.2619 aa(:,:,3,3,1,1) = 0.0778 0.2560 0.0087 0.9143 aa(:,:,4,3,1,1) = 0.0072 0.6919 0.1890 0.1571 aa(:,:,5,3,1,1) = 0.8836 0.0129 0.3923 0.3639 aa(:,:,6,3,1,1) = 0.1934 0.1431 0.1208 0.9684 aa(:,:,7,3,1,1) = 0.4079 0.8224 0.8316 0.4228 aa(:,:,1,4,1,1) = 0.4710 0.5788 0.5508 0.4687 aa(:,:,2,4,1,1) = 0.7211 0.1352 0.9334 0.0255 aa(:,:,3,4,1,1) = 0.9932 0.8575 0.2223 0.2574 aa(:,:,4,4,1,1) = 0.1653 0.3245 0.9042 0.5724 aa(:,:,5,4,1,1) = 0.1789 0.3322 0.2067 0.7597 aa(:,:,6,4,1,1) = 0.3691 0.0749 0.3866 0.8085 aa(:,:,7,4,1,1) = 0.9338 0.0011 0.7774 0.1019 aa(:,:,1,5,1,1) = 0.6751 0.8667 0.5495 0.0232 aa(:,:,2,5,1,1) = 0.9709 0.5201 0.4510 0.6657 aa(:,:,3,5,1,1) = 0.4342 0.8923 0.8578 0.0066 aa(:,:,4,5,1,1) = 0.9927 0.5489 0.9356 0.0905 aa(:,:,5,5,1,1) = 0.7220 0.1775 0.5724 0.2234 aa(:,:,6,5,1,1) = 0.6773 0.8972 0.9848 0.9680 aa(:,:,7,5,1,1) = 0.1997 0.7110 0.8403 0.1463 aa(:,:,1,6,1,1) = 0.3191 0.8865 0.6177 0.6374 aa(:,:,2,6,1,1) = 0.0059 0.0880 0.6739 0.0232 aa(:,:,3,6,1,1) = 0.2191 0.6700 0.1885 0.3808 aa(:,:,4,6,1,1) = 0.3154 0.2193 0.9912 0.6073 aa(:,:,5,6,1,1) = 0.3373 0.7867 0.5839 0.2687 aa(:,:,6,6,1,1) = 0.3811 0.1301 0.1608 0.7425 aa(:,:,7,6,1,1) = 0.0096 0.3276 0.7308 0.3163 aa(:,:,1,1,2,1) = 0.8189 0.5759 0.0851 0.7790 aa(:,:,2,1,2,1) = 0.2365 0.2786 0.5076 0.3558 aa(:,:,3,1,2,1) = 0.9507 0.4665 0.5161 0.0142 aa(:,:,4,1,2,1) = 0.2751 0.8958 0.0618 0.1880 aa(:,:,5,1,2,1) = 0.4546 0.6650 0.2675 0.7073 aa(:,:,6,1,2,1) = 0.2902 0.9054 0.8072 0.7282 aa(:,:,7,1,2,1) = 0.1951 0.2063 0.6589 0.9684 aa(:,:,1,2,2,1) = 0.6936 0.6107 0.3873 0.2177 aa(:,:,2,2,2,1) = 0.8369 0.3446 0.3256 0.5721 aa(:,:,3,2,2,1) = 0.3159 0.4124 0.8811 0.9679 aa(:,:,4,2,2,1) = 0.5061 0.6787 0.6418 0.2087 aa(:,:,5,2,2,1) = 0.5359 0.3341 0.8670 0.5434 aa(:,:,6,2,2,1) = 0.3430 0.3301 0.9442 0.8855 aa(:,:,7,2,2,1) = 0.7702 0.7577 0.0428 0.6860 aa(:,:,1,3,2,1) = 0.5163 0.4864 0.1182 0.2468 aa(:,:,2,3,2,1) = 0.5189 0.3861 0.1708 0.9316 aa(:,:,3,3,2,1) = 0.8415 0.2122 0.6357 0.9771 aa(:,:,4,3,2,1) = 0.4309 0.9644 0.9911 0.0487 aa(:,:,5,3,2,1) = 0.2031 0.2960 0.2076 0.6558 aa(:,:,6,3,2,1) = 0.4637 0.0315 0.3079 0.4688 aa(:,:,7,3,2,1) = 0.1184 0.8215 0.8250 0.9187 aa(:,:,1,4,2,1) = 0.7432 0.4143 0.9668 0.7088 aa(:,:,2,4,2,1) = 0.8080 0.0981 0.5993 0.7263 aa(:,:,3,4,2,1) = 0.8209 0.3296 0.9731 0.2097 aa(:,:,4,4,2,1) = 0.9623 0.8104 0.3869 0.0156 aa(:,:,5,4,2,1) = 0.3327 0.9715 0.8255 0.4920 aa(:,:,6,4,2,1) = 0.2257 0.7954 0.7444 0.5075 aa(:,:,7,4,2,1) = 0.3779 0.6433 0.9942 0.3442 aa(:,:,1,5,2,1) = 0.3112 0.6291 0.8811 0.4081 aa(:,:,2,5,2,1) = 0.3662 0.8240 0.9516 0.3380 aa(:,:,3,5,2,1) = 0.7363 0.7501 0.5754 0.9715 aa(:,:,4,5,2,1) = 0.2202 0.0821 0.6867 0.3309 aa(:,:,5,5,2,1) = 0.7259 0.8840 0.5311 0.5595 aa(:,:,6,5,2,1) = 0.2494 0.1811 0.6107 0.3819 aa(:,:,7,5,2,1) = 0.5594 0.2914 0.4720 0.0359 aa(:,:,1,6,2,1) = 0.2703 0.6119 0.0300 0.9868 aa(:,:,2,6,2,1) = 0.7683 0.8902 0.0345 0.7701 aa(:,:,3,6,2,1) = 0.8499 0.1076 0.1160 0.2910 aa(:,:,4,6,2,1) = 0.2498 0.1215 0.2808 0.3341 aa(:,:,5,6,2,1) = 0.5208 0.9317 0.1169 0.5411 aa(:,:,6,6,2,1) = 0.5332 0.6614 0.2344 0.7782 aa(:,:,7,6,2,1) = 0.8292 0.4059 0.8855 0.7340 aa(:,:,1,1,3,1) = 0.1475 0.1281 0.4092 0.5867 aa(:,:,2,1,3,1) = 0.5576 0.5182 0.4758 0.1974 aa(:,:,3,1,3,1) = 0.8660 0.9045 0.5953 0.3883 aa(:,:,4,1,3,1) = 0.7145 0.7005 0.8189 0.8880 aa(:,:,5,1,3,1) = 0.2933 0.4757 0.3140 0.5705 aa(:,:,6,1,3,1) = 0.9365 0.1325 0.8497 0.4368 aa(:,:,7,1,3,1) = 0.1702 0.2913 0.9423 0.8083 aa(:,:,1,2,3,1) = 0.8312 0.2277 0.0579 0.6564 aa(:,:,2,2,3,1) = 0.4023 0.9761 0.3809 0.6174 aa(:,:,3,2,3,1) = 0.8622 0.2936 0.4446 0.1018 aa(:,:,4,2,3,1) = 0.2360 0.7648 0.8694 0.7165 aa(:,:,5,2,3,1) = 0.8384 0.4192 0.2480 0.8295 aa(:,:,6,2,3,1) = 0.6718 0.0592 0.9338 0.1966 aa(:,:,7,2,3,1) = 0.8897 0.2830 0.7106 0.5903 aa(:,:,1,3,3,1) = 0.9580 0.6212 0.3946 0.4152 aa(:,:,2,3,3,1) = 0.0863 0.4451 0.6591 0.0679 aa(:,:,3,3,3,1) = 0.2488 0.3158 0.8474 0.7895 aa(:,:,4,3,3,1) = 0.5696 0.7402 0.4118 0.1534 aa(:,:,5,3,3,1) = 0.7399 0.9697 0.9325 0.5973 aa(:,:,6,3,3,1) = 0.2260 0.4608 0.1231 0.5655 aa(:,:,7,3,3,1) = 0.7135 0.8162 0.5829 0.2829 aa(:,:,1,4,3,1) = 0.2280 0.6065 0.9647 0.2488 aa(:,:,2,4,3,1) = 0.3945 0.8637 0.5233 0.8063 aa(:,:,3,4,3,1) = 0.3877 0.4001 0.6876 0.4807 aa(:,:,4,4,3,1) = 0.4075 0.7850 0.9148 0.2913 aa(:,:,5,4,3,1) = 0.8466 0.7304 0.9182 0.3485 aa(:,:,6,4,3,1) = 0.1086 0.3198 0.5749 0.2393 aa(:,:,7,4,3,1) = 0.0080 0.3644 0.8495 0.6990 aa(:,:,1,5,3,1) = 0.9230 0.3886 0.6770 0.5804 aa(:,:,2,5,3,1) = 0.2152 0.0640 0.3118 0.8238 aa(:,:,3,5,3,1) = 0.9430 0.6078 0.4243 0.5352 aa(:,:,4,5,3,1) = 0.2183 0.5573 0.4398 0.3094 aa(:,:,5,5,3,1) = 0.7829 0.8540 0.0637 0.1534 aa(:,:,6,5,3,1) = 0.1178 0.3432 0.1694 0.1185 aa(:,:,7,5,3,1) = 0.3388 0.8192 0.6985 0.0298 aa(:,:,1,6,3,1) = 0.0668 0.7147 0.9702 0.7679 aa(:,:,2,6,3,1) = 0.2021 0.4049 0.4171 0.0053 aa(:,:,3,6,3,1) = 0.4182 0.8767 0.8101 0.5869 aa(:,:,4,6,3,1) = 0.1349 0.0910 0.6505 0.2284 aa(:,:,5,6,3,1) = 0.2433 0.5616 0.7218 0.0999 aa(:,:,6,6,3,1) = 0.4142 0.1875 0.1181 0.1276 aa(:,:,7,6,3,1) = 0.8205 0.8269 0.8212 0.7020 aa(:,:,1,1,4,1) = 0.2184 0.7743 0.8171 0.9447 aa(:,:,2,1,4,1) = 0.1003 0.4166 0.6049 0.1780 aa(:,:,3,1,4,1) = 0.7637 0.6540 0.0580 0.7798 aa(:,:,4,1,4,1) = 0.4828 0.9462 0.7054 0.5330 aa(:,:,5,1,4,1) = 0.7148 0.8188 0.3431 0.9555 aa(:,:,6,1,4,1) = 0.6420 0.1937 0.1060 0.8341 aa(:,:,7,1,4,1) = 0.4397 0.0966 0.4869 0.5935 aa(:,:,1,2,4,1) = 0.3378 0.8517 0.3280 0.8790 aa(:,:,2,2,4,1) = 0.4284 0.0280 0.5643 0.4047 aa(:,:,3,2,4,1) = 0.8089 0.6478 0.6408 0.7615 aa(:,:,4,2,4,1) = 0.5792 0.9681 0.8072 0.0976 aa(:,:,5,2,4,1) = 0.2058 0.4168 0.1854 0.5570 aa(:,:,6,2,4,1) = 0.4693 0.3453 0.5363 0.6000 aa(:,:,7,2,4,1) = 0.0021 0.9970 0.9612 0.1760 aa(:,:,1,3,4,1) = 0.1343 0.7042 0.7344 0.3844 aa(:,:,2,3,4,1) = 0.8783 0.4606 0.3488 0.9886 aa(:,:,3,3,4,1) = 0.3947 0.2577 0.0076 0.3230 aa(:,:,4,3,4,1) = 0.8727 0.2018 0.1880 0.1431 aa(:,:,5,3,4,1) = 0.6860 0.9694 0.7745 0.8662 aa(:,:,6,3,4,1) = 0.4455 0.0246 0.7860 0.6146 aa(:,:,7,3,4,1) = 0.3367 0.5035 0.4020 0.8509 aa(:,:,1,4,4,1) = 0.1915 0.3449 0.7628 0.4733 aa(:,:,2,4,4,1) = 0.3415 0.0604 0.3876 0.0146 aa(:,:,3,4,4,1) = 0.9477 0.3509 0.2018 0.8767 aa(:,:,4,4,4,1) = 0.5511 0.7461 0.1928 0.2614 aa(:,:,5,4,4,1) = 0.4761 0.9826 0.6740 0.2726 aa(:,:,6,4,4,1) = 0.4249 0.6074 0.7198 0.8782 aa(:,:,7,4,4,1) = 0.8583 0.3520 0.6886 0.3848 aa(:,:,1,5,4,1) = 0.4866 0.5627 0.7105 0.4507 aa(:,:,2,5,4,1) = 0.5819 0.5400 0.9927 0.7450 aa(:,:,3,5,4,1) = 0.4943 0.1198 0.4322 0.3524 aa(:,:,4,5,4,1) = 0.4075 ...

Assertion failed.

### Community Treasure Hunt

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

Start Hunting!