Check if the difference between the neighbors of a cell in a vector above
a threshold where all the neighbors are non-zeros
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:
N = 5; % 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
No comments:
Post a Comment