开发者

Deleting matrix elements efficiently

I want to efficiently delete a lot of data from the beginning of a matrix of dimension 2*n. The matrix looks like this:

x1 x2
x3 x开发者_StackOverflow4
...
...

I want to delete all rows that have the the first element of a row that is smaller than some number and stop when a row isn't smaller (the elements are in numerical order)

What I do at the moment is slow:

while 1 
   if list{i}(1) <= someNumber
      list{i}(1,:) = []
   else
      break;
   end
end

There must be a neat way of doing this quickly in MATLAB?

Thank you.


One way is to just compare the entire first column in one go and then delete, i.e.

rows2delete = list{i}(:,1) <= someNumber; %# creates logical array with 1 for deletion
list{i}(rows2delete,:) = []; %# delete some rows, all corresponding cols
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜