How to delete the row that contains specific numbers on the cells

1 回表示 (過去 30 日間)
Samantha Chong
Samantha Chong 2016 年 1 月 12 日
コメント済み: Walter Roberson 2016 年 1 月 12 日
Hi, I have a matrix of 80x2, each cell contains certain values. My aim is to delete the rows in which both cells in the rows contain the values "-99.9". An example of the first 3 rows is as attached.

採用された回答

Walter Roberson
Walter Roberson 2016 年 1 月 12 日
If you have R2015a or later, and if your values are all numeric and the same size, then
to_delete_mask = ismembertol(cell2mat(YourCell), [-99.9, -99.9], 'ByRows', true);
YourCell(to_delete_mask,:) = [];
If you are using an earlier release you will need to test abs() of the difference to -99.9 against a small tolerance.
It may appear that you should be able to just compare your values to -99.9 but you cannot do so because of floating point precision roundoff; what looks like exactly -99.9 is not exactly that because it is not possible to exactly represent the fraction 9/10 in finite binary floating point.
  2 件のコメント
Samantha Chong
Samantha Chong 2016 年 1 月 12 日
Hi, thanks for your reply :)
I'm currently using R2011a and I've tested with ismembertol but it can't recognize the function. So, I guess I should go for the second option which you've suggested. However, I don't really understand the 2nd option. It would be great if you could show me the related codes :)
Cheers
Walter Roberson
Walter Roberson 2016 年 1 月 12 日
tolerance = 1e-12;
to_delete_mask = all( abs(cell2mat(YourCell) - (-99.9)) < tolerence, 2);
YourCell(to_delete_mask,:) = [];

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by