MATLAB Answers

How to find missing values in a table and delete the row along with all other associated rows

2 ビュー (過去 30 日間)
Leo Tu
Leo Tu 2021 年 7 月 2 日
コメント済み: Leo Tu 2021 年 7 月 2 日
I have a imported data into a table named V in MATLAB. The first column contains dates in the form 01/01/1987 00:00, everyday for 31 years. The other columns are variables.
Some of the variables data is missing in column 3 (NaN in the cells) and I would like to delete all rows with missing data but also then check what year that row was and delete all other rows of the same year.
There are too many rows to do this by inspection so I cannot use rmmissing(V) as I won't be able to check what was deleted and then delete all other rows of the same year. By the same reason I also cannot use:
V(V.(3) == 0, :) = [];
Any help would be much appreciated.


Cris LaPierre
Cris LaPierre 2021 年 7 月 2 日
It seems a solution will need to be highly customized to your particular data set. Since you haven't shared your data, here's my best guess.
% Find rows missing data in var3
ind = ismissing(V.(3));
% Extract the year corresponding to missing data
yr = unique(year(V{ind,1}));
% Find rows of table from same years as missing data
rm = ismember(year(V.(1)),yr);
% delete
V(rm,:) = [];
  1 件のコメント
Leo Tu
Leo Tu 2021 年 7 月 2 日
Thank you @Cris LaPierre it worked exactly how I needed it to!


その他の回答 (0 件)




Community Treasure Hunt

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

Start Hunting!

Translated by