有效删除矩阵元素 [英] Deleting matrix elements efficiently

查看:117
本文介绍了有效删除矩阵元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从2 * n维矩阵的开头有效地删除很多数据.矩阵如下所示:

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 x4
...
...

我要删除所有行的第一个元素小于某个数字的所有行,并在行不小于(元素按数字顺序)时停止.

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)

此刻我做的很慢:

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

在MATLAB中一定有一种快速完成此操作的巧妙方法吗?

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

谢谢.

推荐答案

一种方法是一次性比较整个第一列,然后删除,即

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

这篇关于有效删除矩阵元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆