How can I index multiple, nonsequential, nonlinearly spaced values?
95 views (last 30 days)
Show older comments
How would I go about indexing the first, sixth, and seventh numbers in an array all with one command?
0 Comments
Answers (2)
Star Strider
on 21 Jan 2016
Use a vector of indices to address them in any order you want:
V = randi(9, 1, 10);
R1 = V([1 5 9]);
R2 = V([6 2 8]);
The same goes for matrices. You ideally should have a separate vector of indices for each array dimension, but since matrices are also addressed linearly, you can also address them using the ind2sub function and its friends. See the documentaiton on Matrices and Arrays for more details.
0 Comments
See Also
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!