Mixing subscripts with linear indices
Show older comments
Generally speaking, I have found that it has always been possible to mix subscript and linear array indexing, as long as the indexing syntax is in the form,
A(subscript_1,subscript_2,...,subscript_n, linear_index).
For example, given,
A = reshape((1:24)*3, [4, 3, 2]);
all of the following are valid ways of indexing the final element in A,
A(4,3,2)
A(4,6)
A(24)
However, I haven't been able to find documentation of this, except of course for the trivial case where n=0. Is it officially supported behavior?
1 Comment
Same example as above, with other cases
A = reshape((1:24)*3, [4, 3, 2])
The linear index can be a vector
A(:,[3 5])
Or a colon
A(2,:)
A(:,:)
Or even an array, which gets stretched into a vector index
A(:,[1:2;1:2])
I too can't find relevant documentation.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!