在使用matlab指定上限/下限后从数组中提取数据

时间:2022-05-05 14:56:51

Is there any method to specify upper and lower limits and extract the data from the array?

有没有任何方法可以指定上限和下限并从数组中提取数据?

or

Is there any function in Matlab available to extract data from the array which fall under specified limits?

Matlab中是否有任何函数可以从阵列中提取属于指定限制的数据?

For example: I have made two sample plots and I have extracted the following data points

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

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

I take each timestamp value from plot B and wanted to add+2.0 and -2.0 and specify them as upper/lower limit. I wanted to find if the timestamp values of A fall under any of the upper/lower limits….

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

2 个解决方案

#1


2  

Try this:

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

The interpretation is: result(m,n) is 1 if the n-th point in A is within +/-tol of the m-th point in B, and 0 otherwise.

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

If you just want to know if each point of A is within the specified range of any of the points in B, use

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

any(result)

With your example data:

使用您的示例数据:

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

#2


0  

What you need is the ismemberf File Exchange submission.

您需要的是ismemberf文件交换提交。

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:

以下是如何使用ismemberf,假设您已下载并且它在您的路径上:

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

#1


2  

Try this:

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

The interpretation is: result(m,n) is 1 if the n-th point in A is within +/-tol of the m-th point in B, and 0 otherwise.

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

If you just want to know if each point of A is within the specified range of any of the points in B, use

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

any(result)

With your example data:

使用您的示例数据:

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

#2


0  

What you need is the ismemberf File Exchange submission.

您需要的是ismemberf文件交换提交。

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:

以下是如何使用ismemberf,假设您已下载并且它在您的路径上:

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