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
Show
4 older comments
Kevin Hellemans
on 24 Apr 2020
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.
Tung Van Nguyen
on 16 May 2021
i like it
David Verrelli
on 29 Jul 2021
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 commentsGroup

Tough Stuff
- 19 Problems
- 7 Finishers
- Make a function that returns its own character count
- love is an n-letter word
- Reverse Boggle
- Cumulative maximum of an array
- Pattern Recognition 3 - Variable Unit and Array Length (including cell arrays)
- Cumulative minimum of an array
- Find the Final State of an Abelian Sandpile
- Decimation - Optimized for speed
- Construct a "diagAdiag" matrix
- Find vampire numbers
- Math with Roman Numerals
- Find similar sequences
- Given two arrays, find the maximum overlap
- Some Assembly Required
- N-Dimensional Array Slice
- Find the stride of the longest skip sequence
- Create initial basic feasible solution for transportation problems -Minimum Cost Method
- Numbers spiral diagonals (Part 2)
- Find the biggest empty box
Problem Recent Solvers243
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!