フィルターのクリア

Delete values in the array

6 ビュー (過去 30 日間)
Conrado Dias
Conrado Dias 2015 年 4 月 11 日
編集済み: Stephen23 2015 年 4 月 13 日
I'm having trouble developing a script. The problem:
In a matrix with positive and negative numbers, delete the values "greater and equal" and "smaller and equal" a certain value. Example:
Delete values above 100 and below -100
if anyone can help.
Thanks.

採用された回答

Stephen23
Stephen23 2015 年 4 月 11 日
編集済み: Stephen23 2015 年 4 月 13 日
Deleting single elements from a matrix does not really make much sense. Lets have a look at a simple case:
>> A = [1,2;3,101;4,5]
A =
1 2
3 101
4 5
If we try to delete the element > 100, then we end up with something that is not a matrix, and cannot be stored in MATLAB:
1 2
3 <- what happens here?
4 5
So what can we do instead of creating that empty space? The answer is one of two things:
1. Replace the value with another value, e.g. zero or NaN:
>> A(A>100) = NaN
A =
1 2
3 NaN
4 5
2. Delete an entire row or column, e.g. here I delete the whole second row:
>> X = any(A>100,2)
X =
0
1
0
>> A(X,:) = []
A =
1 2
4 5
  1 件のコメント
Conrado Dias
Conrado Dias 2015 年 4 月 13 日
Thank you, was of great help.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by