How to Remove Rows in Table

22 vues (au cours des 30 derniers jours)
Minjun Seo
Minjun Seo le 12 Août 2019
Modifié(e) : Adam Danz le 12 Août 2019
Hi, I have a data table here.
Let's say that I want to get rid of the people that does not like animal, signified by a blank space instead of a Y.
How do I make a new data table that removes these rows and forms a new table that only contains the Y.
Thank you!

Réponse acceptée

Adam Danz
Adam Danz le 12 Août 2019
Read in the data; determine which rows are empty under "LikesAnimals"; then remove those rows.
t = readtable('data table.xlsx','ReadRowNames',true); % use full path if possible
noLikeIdx = cellfun(@isempty,t.LikesAnimals);
t(noLikeIdx, :) = [];
  6 commentaires
Minjun Seo
Minjun Seo le 12 Août 2019
Actually, it is represented as NaN, is there a way to similarly filter out those with NaN?
Adam Danz
Adam Danz le 12 Août 2019
Modifié(e) : Adam Danz le 12 Août 2019
Yes. In my answer above, the variable "noLikeIdx" is an index of rows that will be eliminated.
Here's how to create an index of rows that have NaN values or values less than 0 based on values stored in a column named "OtherData".
rowIdx = isnan(t.OtherData) | t.OtherData < 0;
% { find nan values} or {values less than 0}

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by