if statement deleting cells

3 ビュー (過去 30 日間)
cormac spillane
cormac spillane 2015 年 4 月 25 日
コメント済み: cormac spillane 2015 年 4 月 25 日
I want to use the if function to delete every row in a matrix D that has a cell with -99.99 , there are a total of 582 rows and 2 colmuns if that helps. Any assistance would be greatly appreciated.
  1 件のコメント
Stephen23
Stephen23 2015 年 4 月 25 日
In MATLAB a cell refers to an element of a cell array, whereas for numeric and characters arrays the individual vlaues are called the elements.

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

採用された回答

Stephen23
Stephen23 2015 年 4 月 25 日
編集済み: Stephen23 2015 年 4 月 25 日
There is one very important point to consider, and that is that checking for equivalence of floating point values is not recommended:
Instead of checking that the value is equal to -99.99 you should check that the values is inside a range of values, or equivalently use a tolerance values in a comparison:
>> tol = 0.01;
>> val = -99.99;
>> D = [1,2,3;4,5,-99.99;6,7,8;9,-99.99,0] % fake data
D =
1 2 3
4 5 -99.99
6 7 8
9 -99.99 0
>> D(any(abs(D-val)<=tol,2),:) = []
D =
1 2 3
6 7 8
This solution uses vectorized code and logical indexing, which will be faster than solving this in a loop. It also extends nicely as the arrays get larger, unlike a loop.
  1 件のコメント
cormac spillane
cormac spillane 2015 年 4 月 25 日
thank you stephen ! that works much better and is logically more sound
cheers cormac

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by