Cody

Problem 43641. Find matrix of indices for multidimensional matrix.

Given some multidimensional matrix A. Get a matrix of the same size as A where all elements are replaced by their index along the kth dimension

Example

Input

A =
ans(:,:,1) =
    1   3
    6   2
ans(:,:,2) =
     6   9
     7   6

Output:

f(A,1) =
ans(:,:,1) =
     1   1
     2   2
ans(:,:,2) =
     1   1
     2   2
f(A,2) =
ans(:,:,1) =
     1   2
     1   2
ans(:,:,2) =
     1   2
     1   2
f(A, 3) =
ans(:,:,1) =
     1   1
     1   1
ans(:,:,2) =
     2   2
     2   2

Solution Stats

84.62% Correct | 15.38% Incorrect
Last Solution submitted on Oct 20, 2018

Problem Comments