vecindex

Version 1.0.0.0 (1.52 KB) by Luís
VECINDEX(M,I) is a simple function that extrats the element indexed by the elements in the vector I.
144 Downloads
Updated 25 Jan 2012

View License

Normal indexing of a element in MATLAB can be done specifying the subscripts of that element or the respective linear index.
>> A=magic(4)
A =

16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1

>> A(2,3)
ans =

10
>> A(10)
ans =

10
However, trying to index a matrix with a vector containing the respective subscripts causes MATLAB to index the matrix several times:

>>A([2,3])
ans =

5 9
This can be done using vecindex(M,I), where M is the matrix to be indexed and I the vector containing the subscripts:

>>vecindex(A,[2,3])
ans =

10
[E,L]=vecindex(A,I) causes the function to return the indexed element E and the respective linear index L.

Cite As

Luís (2024). vecindex (https://www.mathworks.com/matlabcentral/fileexchange/34761-vecindex), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Matrix Indexing in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0