Azzera filtri
Azzera filtri

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

5 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Star Strider
Star Strider il 18 Gen 2022
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 Commenti
Image Analyst
Image Analyst il 18 Gen 2022
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 il 18 Gen 2022
@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.)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by