Reputation: 55
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 incorrect data. These indexes are stored in another variable. How do i remove the rows (date and value) corresponding to the indices?
Thanks.
Upvotes: 1
Views: 6171
Reputation: 1662
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
Upvotes: 5