Usage:
ind = array2ind(SIZE, COORDINATES_AS_ARRAY)
Example:
g = magic(5);
ind = array2ind([5 5], [3 2])
g(ind)
returns the same value as if you had called
g(3,2)
Useful for when the coordinates for a matrix element are stored as an array and avoids the current method of:
b = [3 2];
g(b(1), b(2))
While this is suitable for some cases, it's not generalized or adaptable to changing sizes of b and g.
Cite As
Greggory (2025). array2ind (https://in.mathworks.com/matlabcentral/fileexchange/32682-array2ind), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2011a
Compatible with any release
Platform Compatibility
Windows macOS LinuxCategories
Find more on Matrices and Arrays in Help Center and MATLAB Answers
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 |
