Delete Specific Rows in Matlab

后端 未结 1 405
再見小時候
再見小時候 2021-01-25 14:03

I have a fairly large 2x2 matrix containing date and temperatures. There is a cluster of NaNs and incorrect data. I used find to get the index that contains the inc

相关标签:
1条回答
  • 2021-01-25 14:38

    fairly large 2x2 matrix makes little or no sense.

    This is part from MATLAB documentation

    You can delete rows and columns from a matrix by assigning the empty array [] to those rows or columns. Start with

    A = magic(4)
    A =
        16     2     3    13
         5    11    10     8
         9     7     6    12
         4    14    15     1
    

    Then, delete the second column of A using

    A(:, 2) = []
    

    This changes matrix A to

    A = 
       16    3   13
        5   10    8
        9    6   12
        4   15    1
    

    Also you can delete multiple rows/columns at once:

    A([1 3],:)=[]
    A =
        5    10     8
        4    15     1
    
    0 讨论(0)
提交回复
热议问题