Cody

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

Solution 2242297

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 = 5 B(:,:,1,1,1) = 0.5893 0.2316 0.5893 0.4139 0.4139 B(:,:,2,1,1) = 0.2316 0.7620 0.1175 0.7902 0.2316 B(:,:,3,1,1) = 0.4139 0.1175 0.7620 0.7620 0.5893 B(:,:,1,2,1) = 0.0953 0.7620 0.7620 0.7620 0.2316 B(:,:,2,2,1) = 0.5893 0.5893 0.7902 0.2316 0.7902 B(:,:,3,2,1) = 0.0953 0.7902 0.7620 0.5891 0.4139 B(:,:,1,3,1) = 0.4139 0.5893 0.2132 0.5893 0.0953 B(:,:,2,3,1) = 0.1175 0.5893 0.5891 0.2316 0.1175 B(:,:,3,3,1) = 0.2132 0.4139 0.7620 0.7902 0.5893 B(:,:,1,4,1) = 0.5893 0.2132 0.2132 0.5891 0.1175 B(:,:,2,4,1) = 0.5891 0.2132 0.2316 0.4139 0.1175 B(:,:,3,4,1) = 0.2316 0.7902 0.2316 0.5891 0.4139 B(:,:,1,1,2) = 0.0953 0.5893 0.5893 0.7620 0.7902 B(:,:,2,1,2) = 0.2316 0.1175 0.7902 0.7902 0.4139 B(:,:,3,1,2) = 0.4139 0.7620 0.2316 0.2132 0.7620 B(:,:,1,2,2) = 0.5891 0.4139 0.2132 0.1175 0.5891 B(:,:,2,2,2) = 0.0953 0.4139 0.2132 0.2132 0.5891 B(:,:,3,2,2) = 0.4139 0.7620 0.1175 0.7620 0.5891 B(:,:,1,3,2) = 0.1175 0.1175 0.7902 0.4139 0.5893 B(:,:,2,3,2) = 0.2132 0.5891 0.7902 0.0953 0.5891 B(:,:,3,3,2) = 0.4139 0.5891 0.5891 0.2316 0.5891 B(:,:,1,4,2) = 0.7902 0.4139 0.2316 0.0953 0.1175 B(:,:,2,4,2) = 0.1175 0.7620 0.2316 0.2132 0.1175 B(:,:,3,4,2) = 0.0953 0.0953 0.5893 0.4139 0.4139 B(:,:,1,1,3) = 0.1175 0.4139 0.2132 0.1175 0.1175 B(:,:,2,1,3) = 0.7902 0.0953 0.2132 0.2132 0.7620 B(:,:,3,1,3) = 0.4139 0.5893 0.2316 0.2316 0.0953 B(:,:,1,2,3) = 0.5891 0.2316 0.4139 0.2132 0.4139 B(:,:,2,2,3) = 0.7902 0.2316 0.4139 0.4139 0.1175 B(:,:,3,2,3) = 0.4139 0.2132 0.0953 0.7902 0.1175 B(:,:,1,3,3) = 0.5891 0.7620 0.5893 0.7620 0.2132 B(:,:,2,3,3) = 0.7902 0.7902 0.5893 0.1175 0.7902 B(:,:,3,3,3) = 0.2316 0.5891 0.7620 0.5891 0.0953 B(:,:,1,4,3) = 0.5891 0.5893 0.2132 0.7902 0.7902 B(:,:,2,4,3) = 0.1175 0.7902 0.1175 0.7620 0.5891 B(:,:,3,4,3) = 0.2132 0.7620 0.7620 0.7902 0.1175 B(:,:,1,1,4) = 0.2316 0.5893 0.2132 0.7620 0.2316 B(:,:,2,1,4) = 0.2132 0.4139 0.7620 0.0953 0.0953 B(:,:,3,1,4) = 0.2316 0.5893 0.0953 0.4139 0.7620 B(:,:,1,2,4) = 0.2316 0.2316 0.7902 0.4139 0.2132 B(:,:,2,2,4) = 0.4139 0.4139 0.7620 0.2132 0.7902 B(:,:,3,2,4) = 0.7620 0.7902 0.7902 0.7902 0.5893 B(:,:,1,3,4) = 0.2132 0.2132 0.0953 0.5893 0.2132 B(:,:,2,3,4) = 0.7902 0.7902 0.0953 0.0953 0.7620 B(:,:,3,3,4) = 0.4139 0.7620 0.5893 0.1175 0.5893 B(:,:,1,4,4) = 0.5893 0.2316 0.1175 0.5893 0.7620 B(:,:,2,4,4) = 0.2316 0.7620 0.5893 0.2316 0.2316 B(:,:,3,4,4) = 0.2316 0.4139 0.4139 0.5891 0.4139 B(:,:,1,1,5) = 0.5893 0.2316 0.2316 0.5893 0.5893 B(:,:,2,1,5) = 0.5891 0.7620 0.5891 0.5893 0.2316 B(:,:,3,1,5) = 0.4139 0.7902 0.7620 0.2132 0.5891 B(:,:,1,2,5) = 0.2316 0.0953 0.5893 0.7902 0.5893 B(:,:,2,2,5) = 0.7620 0.1175 0.2316 0.5891 0.5891 B(:,:,3,2,5) = 0.5893 0.7620 0.7902 0.2132 0.5893 B(:,:,1,3,5) = 0.0953 0.5893 0.1175 0.7902 0.0953 B(:,:,2,3,5) = 0.7902 0.0953 0.7902 0.0953 0.4139 B(:,:,3,3,5) = 0.0953 0.2316 0.5891 0.0953 0.1175 B(:,:,1,4,5) = 0.2132 0.4139 0.1175 0.2316 0.7902 B(:,:,2,4,5) = 0.0953 0.5893 0.7902 0.0953 0.2316 B(:,:,3,4,5) = 0.2316 0.0953 0.0953 0.0953 0.7902 B(:,:,1,1,6) = 0.1175 0.5891 0.5893 0.4139 0.7902 B(:,:,2,1,6) = 0.4139 0.2316 0.4139 0.1175 0.0953 B(:,:,3,1,6) = 0.4139 0.7902 0.2132 0.2132 0.1175 B(:,:,1,2,6) = 0.7620 0.7620 0.1175 0.7620 0.4139 B(:,:,2,2,6) = 0.4139 0.2132 0.2132 0.7902 0.7620 B(:,:,3,2,6) = 0.5891 0.4139 0.4139 0.7620 0.5893 B(:,:,1,3,6) = 0.5893 0.5893 0.2132 0.5891 0.2132 B(:,:,2,3,6) = 0.5891 0.5893 0.7620 0.7902 0.4139 B(:,:,3,3,6) = 0.2132 0.5891 0.1175 0.7620 0.7902 B(:,:,1,4,6) = 0.5891 0.5893 0.1175 0.0953 0.2316 B(:,:,2,4,6) = 0.4139 0.1175 0.4139 0.5891 0.7902 B(:,:,3,4,6) = 0.7902 0.0953 0.2316 0.7620 0.4139 B(:,:,1,1,7) = 0.5891 0.7902 0.7902 0.4139 0.7620 B(:,:,2,1,7) = 0.5893 0.5893 0.4139 0.7902 0.2316 B(:,:,3,1,7) = 0.0953 0.1175 0.2316 0.4139 0.4139 B(:,:,1,2,7) = 0.2132 0.0953 0.2316 0.2132 0.2132 B(:,:,2,2,7) = 0.4139 0.0953 0.5893 0.4139 0.2316 B(:,:,3,2,7) = 0.4139 0.5891 0.2316 0.5891 0.5893 B(:,:,1,3,7) = 0.7620 0.2316 0.5893 0.2132 0.5891 B(:,:,2,3,7) = 0.0953 0.7620 0.7620 0.2132 0.1175 B(:,:,3,3,7) = 0.5893 0.7620 0.0953 0.1175 0.0953 B(:,:,1,4,7) = 0.7620 0.7620 0.2316 0.7902 0.4139 B(:,:,2,4,7) = 0.7620 0.2132 0.5893 0.2132 0.7620 B(:,:,3,4,7) = 0.1175 0.5891 0.0953 0.4139 0.2132 B(:,:,1,1,8) = 0.4139 0.2132 0.5891 0.2316 0.4139 B(:,:,2,1,8) = 0.4139 0.4139 0.0953 0.7902 0.1175 B(:,:,3,1,8) = 0.5891 0.5893 0.0953 0.1175 0.5893 B(:,:,1,2,8) = 0.5891 0.5891 0.0953 0.2316 0.7620 B(:,:,2,2,8) = 0.5893 0.0953 0.2316 0.7902 0.0953 B(:,:,3,2,8) = 0.5893 0.1175 0.7620 0.1175 0.5891 B(:,:,1,3,8) = 0.7620 0.7902 0.5893 0.7902 0.5891 B(:,:,2,3,8) = 0.7620 0.5893 0.2132 0.5891 0.7902 B(:,:,3,3,8) = 0.2132 0.1175 0.5891 0.5893 0.2316 B(:,:,1,4,8) = 0.7902 0.7902 0.2316 0.2132 0.4139 B(:,:,2,4,8) = 0.0953 0.7620 0.2316 0.1175 0.2132 B(:,:,3,4,8) = 0.7620 0.0953 0.7620 0.2132 0.2132

Assertion failed.

### Community Treasure Hunt

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

Start Hunting!