how to pick a colum vector from a matrix

Discussion in 'MATLAB' started by marc valente, Dec 8, 2006.

  1. marc valente

    marc valente Guest

    I was just woundering if it is posible to pick out a colum vector
    from a matirx. That is if I just wanted the jth colum in an nxn
    matrix is there a way to assing it to a variable?
     
    marc valente, Dec 8, 2006
    #1
    1. Advertisements

  2. marc valente

    mamdouh Guest

    Hi
    Please see the following example it it helps

    %data
    A=[1 2 3; 4 5 6; 7 8 9];
    %results
    column1=A:),1);
    column2=A:),2);
    column3=A:),3);
    Mamdouh

    regards
     
    mamdouh, Dec 8, 2006
    #2
    1. Advertisements

  3. additionally, if you want just rows you could say (r,:) where r is
    the row you desire. if you want several rows or columns (a submatrix)
    try (1:3,:) which would be the first three rows or :),2:5) which
    would be columns 2-5. good luck
     
    bahhhhhhhhhhh, Dec 8, 2006
    #3
  4. marc valente

    us Guest

    marc valente:
    <SNIP cotton-picking - column-picking...

    one of the many solutions

    % the matrix
    m=magic(7)
    % the picking index/indices
    ix=[1:3,5,7];
    % the col submat
    mc=m:),ix)
    % the row submat
    mr=m(ix,:)

    us
     
    us, Dec 8, 2006
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.