Remove a column from a matrix in GNU Octave

前端 未结 4 758
深忆病人
深忆病人 2021-02-02 05:45

In GNU Octave, I want to be able to remove specific columns from a matrix. In the interest of generality. I also want to be able to remove specific rows from a matrix.

4条回答
  •  星月不相逢
    2021-02-02 06:28

    How to remove multiple columns in octave:

    How to remove columns 2 and 4:

    columns_to_remove = [2 4];
    matrix(:,columns_to_remove)=[]
    

    Illustrated:

    mymatrix = eye(5)
    mymatrix =
    
       1   0   0   0   0
       0   1   0   0   0
       0   0   1   0   0
       0   0   0   1   0
       0   0   0   0   1
    
    
    
    columns_to_remove = [2 4];
    
    mymatrix(:,columns_to_remove)=[]
    
    
    mymatrix =
    
       1   0   0
       0   0   0
       0   1   0
       0   0   0
       0   0   1 
    

提交回复
热议问题