deleting a full colum using

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

1 个评论

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

请先登录,再进行评论。

 采纳的回答

Jan
Jan 2013-3-17
编辑:Jan 2013-3-17
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, :) = []

更多回答(1 个)

Locks
Locks 2013-3-17

0 个投票

thanks!

2 个评论

Sven
Sven 2013-3-17
编辑:Sven 2013-3-17
Sven, you're giving me a bad name... please hit the "Accept Answer" button when an answer solves your problem.
(but feel free to say thanks in a comment (like this one) rather than making a new answer)
Sven, if the answer helped, click on accept this answer. Also, to add a comment, click on comment on this answer just under the answer.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by