Problem 375. N-Dimensional Array Slice
Given an N-dimensional array, A, an index, I, and a dimension, d, return the I th elements of A in the d dimension.
For Example,
array_slice( A, 5, 3 )
is equivalent to
A(:,:,5)
Note: eval and str2func cannot be used. This is a Cody restriction.
Solution Stats
Problem Comments
-
7 Comments
How do do want to handle when the index is bigger than the size of the array? In solution 2 or 3 you enter a 5x5 array, but request slice index 10.
i like it
Massimo Zanetti & Kevin Hellemans: in Test 3 the value 10 is entered as the dimension argument (not the index argument, which has a value of 1).
Thus in Test 3 the general solution would be A(:, :, :, :, :, :, :, :, :, 1).
—DIV
Solution Comments
Show commentsProblem Recent Solvers230
Suggested Problems
-
Back to basics 6 - Column Vector
1075 Solvers
-
748 Solvers
-
Implement a bubble sort technique and output the number of swaps required
321 Solvers
-
Remove entire row and column in the matrix containing the input values
407 Solvers
-
Sum the numbers on the main diagonal
590 Solvers
More from this Author56
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!