Asked by Locks
on 17 Mar 2013

I have a matrix with several optionprice data. Now I am trying to delete rows based on a for loop and if criteria. if the value of column 8 is >1.1 or <0.9, the whole row should be deletet. I have used the following code, but I always get an error message:

for i=1:numel(matrix)

if(matrix(i,8)>1.1)

matrix(i,:) = []; end

end

why does that no work and what ways are there to delete those rows? the matrix is a double matrix

*No products are associated with this question.*

Answer by Jan Simon
on 17 Mar 2013

Edited by Jan Simon
on 17 Mar 2013

Accepted answer

`numel(matrix)` is the number of all elements. When you have deleted some rows already, the matrix has less elements and `matrix(i,8)` might be not existing anymore already.

You do not need a loop, to solve this problem:

matrix(matrix(:, 8) > 1.1, :) = []

Answer by Locks
on 17 Mar 2013

thanks!

Azzi Abdelmalek
on 17 Mar 2013

**comment on this answer** just under the answer.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 1 Comment

## Jan Simon (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/67487#comment_136962

Please post the error message whenever you explain, that there is an error.