Search code examples
matlabmatrixextractsubmatrix

Extracting part of a matrix


I have a matrix say (𝗉+𝗊) 𝗑 𝗋 order, I want to extract first 𝗉 𝗑 𝗋 order matrix, like say

`A matrix,

I want to extract first

required


Solution

  • As suggested by rahnema1, you can use Matrix Indexing in matlab as follows:

    partA = A(1:p, :)
    

    or for your specific example:

    partA = A(1:3, :)
    

    Explanation

    • 1:p: selects all rows between 1 and p.
    • : selects all columns.

    Further reading

    As this seems a basic question to me, it may be useful to have a look at the Getting Started tutorial.