Clear Filters
Clear Filters

Delete values in the array

6 views (last 30 days)
Conrado Dias
Conrado Dias on 11 Apr 2015
Edited: Stephen23 on 13 Apr 2015
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.

Accepted Answer

Stephen23
Stephen23 on 11 Apr 2015
Edited: Stephen23 on 13 Apr 2015
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

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!