0

有什么方法可以指定上限和下限并从数组中提取数据吗?

或者

Matlab 中是否有任何函数可用于从数组中提取低于指定限制的数据?

例如:我制作了两个样本图,并提取了以下数据点

A=[1 2.2 4.3  5.3 12.0 34.1 43.3] %Time stamp values from the first plot
B=[1.4 7.6 35.2] %Time stamp values from the second plot

我从情节 B 中获取每个时间戳值,并希望添加 +2.0 和 -2.0 并将它们指定为上限/下限。我想知道 A 的时间戳值是否低于任何上限/下限……。

4

2 回答 2

2

尝试这个:

tol = 2;
result = bsxfun(@ge,A(:).',B(:)-tol) & bsxfun(@le,A(:).',B(:)+tol);

解释是:result(m,n)如果 in 的第 n 个点在的第 m 个点的A+/- 范围内,则为 1 ,否则为 0。tolB

如果您只想知道 的每个点是否在 中的任何A的指定范围内,请使用B

any(result)

使用您的示例数据:

>> A = [1 2.2 4.3 5.3 12.0 34.1 43.3];
>> B = [1.4 7.6 35.2];
>> result

result =

     1     1     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     1     0

>> any(result)

ans =

     1     1     0     0     0     1     0
于 2013-10-30T10:21:54.980 回答
0

What you need is the ismemberf File Exchange submission.

It basically lets you check whether there are matching values within your tolerance.

Example:

Here is how you can use ismemberf assuming you have downloaded it and it is on your path:

A = [1 2.2 4.3 5.3 12.0 34.1 43.3] 
B = [1.4 7.6 35.2]
[lia, locb] = ismemberf(A,B,'tol',2)

Will give:

lia =

     1     1     0     0     0     1     0


locb =

     1     1     0     0     0     3     0
于 2013-10-30T10:27:36.183 回答