How do I extract non sequential rows of a matrix without using a for loop?

2 views (last 30 days)
I have a very large matrix (m1), and I want to create a new matrix (m2) using certain rows of m1. The list of rows I want is contained in a 1xN matrix called "list". Naively, I would expect the command to be
m2 = [m1(list,:)]
However, matlab will not accept a matrix as an index. (I receive the error "Subscript indices must either be real positive integers or logicals.")
Any help would be appreciated.
For context: The matrix m1 is too large for me to attempt this exercise by hand -- it contains 100000 rows. Also, there is no obvious mathematical relationship among the entries in "list".
  3 Comments
Ryan Melvin
Ryan Melvin on 2 Oct 2013
Actually, you were correct. List was an output from a program that starts counting from 0; whereas, matlab's indices count from 1. I added 1 to every member of list, and now things work as expected. Thank you.

Sign in to comment.

Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!