1
votes

I have a NxM matrix where some rows has the code 999 for missing values. All matrix elements are temperature over land, so sensible numbers are between -100 and 100. Each row represents one 'grid' over time, so if the first element in, say row 10 is 999, then the rest are also.

I want to delete all rows with numbers larger than for example 100. A toy example that gives me the right answer is:

A = [1 1; 3 3; 999 999; 4 4; 999 999]
A(A(:,:)>100)=[]
reshape(A,3,2)

I do not like that the matrix A is transformed in line 2 so that I have to do the reshape.

Is there a better way to delete, in this case, rows 3 and 5?

1

1 Answers

2
votes

You can use array indexing with any (or all if only removing rows with all values greater than 100), and using the second dim argument (since removing rows):

>> A = [1 1; 3 3; 999 999; 4 4; 999 999]
>> A(not(any(A>100,2)),:)

ans =

 1     1
 3     3
 4     4