フィルターのクリア

How do I crop a matrix in MATLAB based on contents of one column?

5 ビュー (過去 30 日間)
Anjali Mishra
Anjali Mishra 2022 年 1 月 18 日
コメント済み: Star Strider 2022 年 1 月 18 日
I have a table saved as matrix with 17 rows and 19 colums. From here I want to crop it to a matrix to keep only those rows which have non-empty 5th column. I want to get rid of all other rows. Can someone please provide insight?

採用された回答

Star Strider
Star Strider 2022 年 1 月 18 日
I am not certain what the matrix is, or whether there are other missing entries in the matrix. If only the 5th column has missing entries, the rmmissing function may be the most efficient way of doing this.
Otherwise, using ‘logical indexing’ would be best —
Lv = ~ismissing(M(:,5));
M_new = M(Lv,:);
where ‘M’ is the matrix.
.
  4 件のコメント
Image Analyst
Image Analyst 2022 年 1 月 18 日
Yeah, since matrices cannot be empty, but (I think) table variables can. However you can check for a matrix value like 0 or 999 or some range of values, like negative values or something.
@Anjali Mishra since you said it works, please "Accept this Answer". 🙂
Star Strider
Star Strider 2022 年 1 月 18 日
@Image Analyst Thank you!
All table variables have to have the same number of rows, so deleting a single entry in any one row will throw an error. However cell arrays can have empty cells, and table arrays with cell array variables can have empty cells. (At least that’s my experience.)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by