删除Matlab中的特定行 [英] Delete Specific Rows in Matlab
问题描述
我有一个相当大的2x2矩阵,其中包含日期和温度.有大量的NaN和不正确的数据.我使用find
来获取包含错误数据的索引.这些索引存储在另一个变量中.如何删除与索引对应的行(日期和值)?
谢谢.
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.
推荐答案
fairly large 2x2 matrix
毫无意义.
这是MATLAB文档的一部分
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
然后,使用删除A的第二列
Then, delete the second column of A using
A(:, 2) = []
这会将矩阵A更改为
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
这篇关于删除Matlab中的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!