vecindex
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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |