vecindex

VECINDEX(M,I) is a simple function that extrats the element indexed by the elements in the vector I.

You are now following this Submission

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 (2026). vecindex (https://www.mathworks.com/matlabcentral/fileexchange/34761-vecindex), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0