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

2 次查看(过去 30 天)
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 个评论
Ryan Melvin
Ryan Melvin 2013-10-2
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by