matrix-indexing

How to select a submatrix (not in any particular pattern) in Matlab

你说的曾经没有我的故事 提交于 2019-11-26 06:36:24
问题 How to select a submatrix (not in any pattern) in Matlab? For example, for a matrix of size 10 by 10, how to select the submatrix consisting of intersection of the 1st 2nd and 9th rows and the 4th and 6th columns? Thanks for any helpful answers! 回答1: TLDR: Short Answer As for your question, suppose you have an arbitrary 10-by-10 matrix A . The simplest way to extract the desired sub-matrix would be with an index vector: B = A([1 2 9], [4 6]); Indexing in MATLAB There's an interesting article

Linear indexing, logical indexing, and all that

醉酒当歌 提交于 2019-11-25 21:58:49
问题 We are used to different forms of indexing in Matlab: standard (using integers along each dimension), logical (using logical values), linear (using a single index to traverse an array with more than one dimension). At first sight, it may appear that these forms are exclusive: an index is either standard, or logical, or linear. However, sometimes there appears to be a blend between several of these forms. For example, >> A = magic(3) A = 8 1 6 3 5 7 4 9 2 >> A(A>5) ans = 8 9 6 7 This is