Cody

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

Solution 1619958

Submitted on 31 Aug 2018 by Jens Kjærgaard Boldsen
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
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 = 4 sz = 2 11 8 11 ndims = 4 szI = 2 11 1 11 ix = 3 ndms = 5 sz = 3 7 11 2 10 ndims = 5 szI = 3 7 1 2 10 ix = 3 ndms = 3 sz = 2 8 11 ndims = 3 szI = 2 1 11 ix = 2 ndms = 4 sz = 10 9 8 4 ndims = 4 szI = 10 9 1 4 ix = 3 ndms = 4 sz = 5 8 6 3 ndims = 4 szI = 5 1 6 3 ix = 2 ndms = 5 sz = 4 5 2 11 5 ndims = 5 szI = 4 5 2 1 5 ix = 4 ndms = 3 sz = 3 10 8 ndims = 3 szI = 1 10 8 ix = 1 ndms = 5 sz = 7 10 5 4 9 ndims = 5 szI = 7 1 5 4 9 ix = 2 ndms = 6 sz = 8 5 4 9 9 10 ndims = 6 szI = 8 5 4 9 9 ix = 6 ndms = 6 sz = 2 4 6 8 8 11 ndims = 6 szI = 2 4 6 8 1 11 ix = 5 ndms = 3 sz = 9 5 9 ndims = 3 szI = 1 5 9 ix = 1 ndms = 5 sz = 11 6 2 2 4 ndims = 5 szI = 11 1 2 2 4 ix = 2 ndms = 2 sz = 6 4 ndims = 2 szI = 1 4 ix = 1 ndms = 2 sz = 6 9 ndims = 2 szI = 1 9 ix = 1 ndms = 4 sz = 2 5 8 5 ndims = 4 szI = 2 1 8 5 ix = 2 ndms = 4 sz = 9 2 4 11 ndims = 4 szI = 9 2 1 11 ix = 3 ndms = 3 sz = 4 8 3 ndims = 3 szI = 4 8 ix = 3 ndms = 3 sz = 7 2 6 ndims = 3 szI = 7 1 6 ix = 2 ndms = 2 sz = 6 10 ndims = 2 szI = 6 1 ix = 2 ndms = 5 sz = 11 3 3 3 8 ndims = 5 szI = 11 3 3 3 ix = 5 ndms = 4 sz = 5 8 5 3 ndims = 4 szI = 5 1 5 3 ix = 2 ndms = 2 sz = 4 10 ndims = 2 szI = 1 10 ix = 1 ndms = 3 sz = 11 7 4 ndims = 3 szI = 11 7 ix = 3 ndms = 2 sz = 10 10 ndims = 2 szI = 1 10 ix = 1 ndms = 4 sz = 5 3 2 7 ndims = 4 szI = 5 3 1 7 ix = 3 ndms = 2 sz = 9 4 ndims = 2 szI = 1 4 ix = 1 ndms = 5 sz = 11 4 11 5 2 ndims = 5 szI = 11 4 1 5 2 ix = 3 ndms = 6 sz = 8 8 5 6 7 6 ndims = 6 szI = 8 1 5 6 7 6 ix = 2 ndms = 4 sz = 8 2 2 5 ndims = 4 szI = 8 2 1 5 ix = 3 ndms = 6 sz = 3 8 4 2 10 9 ndims = 6 szI = 3 8 4 1 10 9 ix = 4

Suggested Problems

Community Treasure Hunt

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

Start Hunting!