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!

 채택된 답변

Adam Danz
Adam Danz 2019년 8월 12일

1 개 추천

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

Minjun Seo
Minjun Seo 2019년 8월 12일
Thank you sir!
Adam Danz
Adam Danz 2019년 8월 12일
Glad I could help!
Minjun Seo
Minjun Seo 2019년 8월 12일
Similarly, if I had another column that either was blank or contained a positive number, is there a way to store those specific rows?
Adam Danz
Adam Danz 2019년 8월 12일
편집: Adam Danz 2019년 8월 12일
You can't have missing numbers. You can have NaNs, but not missing. If the numbers are represented as strings, then you can have missing strings. Is that the case? are the numbers represented as strings ('5') rather than numeric (5)?
Or perhaps the column is a cell array (you can also have empty cells).
The solution will depend on what you're working with: number, strings, cells, something else?
Minjun Seo
Minjun Seo 2019년 8월 12일
Actually, it is represented as NaN, is there a way to similarly filter out those with NaN?
Adam Danz
Adam Danz 2019년 8월 12일
편집: Adam Danz 2019년 8월 12일
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}

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

질문:

2019년 8월 12일

편집:

2019년 8월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by