Delete values in the array

6 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by