检查向量中所有单元的邻居之间的差异是否高于所有邻居均为非零的阈值 [英] Check if the difference between the neighbors of a cell in a vector above a threshold where all the neighbors are non-zeros

查看:88
本文介绍了检查向量中所有单元的邻居之间的差异是否高于所有邻居均为非零的阈值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

K=[1 1 1 2 1 2 10 4 2 10 0 5 1]是一个向量,我想将K中的第7个元素的值与该值的邻居进行比较,其中邻居是每边该元素旁边的6个元素.因此,对于K,第7个元素为10,其邻居为1 1 1 2 1 2(左邻居)和4 2 10 4 5 1 1(右邻居).如果第7个值与其每个邻居的差大于a某个阈值,那么我将做某事,例如X = 1,否则,我将做另一件事,例如X = 2. 因此,在下面的示例中,我将阈值设置为3,因此对于K,第7个元素值是10,并且它与它的两个邻居之间的差10,5大于阈值3,所以X将是1.比较X = 1,因为有两个元素带有diff.大于T inc的第11个元素0,但是如果K=[8 7 8 9 7 7 10 7 7 8 0 9 8]则X = 2,尽管差.在它和第11个元素之间是> T,但这是因为第11个元素是零0.

K=[1 1 1 2 1 2 10 4 2 10 0 5 1] is a vector, I want to compare the value of the 7th element in K with the neighbours of this value, where the neighbours are 6 elements next to this element in each side. So for K, the 7th element is 10 and the neighbours are 1 1 1 2 1 2 (left neighbours) and 4 2 10 4 5 1 (right neighbours).If the difference between the 7th value and each of its neighbours is above a certain threshold then I'll do something e.g X=1, if not then I'll do another thing e.g X=2. So in my example below I set the threshold to 3, so for K the 7th element value is 10 and the difference between it and two of its neighbours 10,5 are more than the threshold value 3 so X will be 1. I'm comparing the X=1 because there are couple of elements with diff. more than T inc the 11th element0, but if K=[8 7 8 9 7 7 10 7 7 8 0 9 8] then X=2 although the diff. between it and the 11th element is >T but this is because the 11th element is zero0.

我正在使用与以下其他问题相关的以下脚本:

I'm using the below script related to my other question found here link

N = 6; % reference index
T = 3; % threshold

V = K;

% formulate if-statement to check for values
% below/above index N and check if any difference
% exceeds the threshold
% the or-statement (because it does not matter if the 
% threshold is exceeded above index N or below)
% is expressed as |

if any((V(1:N-1)-V(N))>T) | any((V(N+1:end)-V(N))>T)
    X = 1;
else
    X = 2;
end

推荐答案

嘿,我认为您应该检查matlab的 diff 内置函数,它可以解决我的问题.

Hey I think you should check diff in-build function of matlab it solves my problem.

这篇关于检查向量中所有单元的邻居之间的差异是否高于所有邻居均为非零的阈值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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