Find

1 次查看(过去 30 天)
AP
AP 2011-7-6
I have a matrix 10000×2, named A. The first column is x and the second column is y. I am trying to find the number of element where the following condition holds:
y<x+b && y>x-b
where b is a constant. I used FIND command to achieve this. I want to make sure it is correct. Thank you very much.
numel(find((A(:,2)<A(:,1)+b) & (A(:,2)>A(:,1)-b)))
I would appreciate quick responses :))))))

回答(2 个)

Matt Fig
Matt Fig 2011-7-6
Use & instead of && when dealing with array comparisons.
Also, this is faster:
sum((A(:,2)<A(:,1)+b) && (A(:,2)>A(:,1)-b))
  1 个评论
AP
AP 2011-7-6
that was soooo quick thanks.

请先登录,再进行评论。


Paulo Silva
Paulo Silva 2011-7-6
a=randi([1 10],10,2); %make up some data
x=a(:,1);
y=a(:,2);
b=5;
sum(y<x+b & y>x-b)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by