Extracting the closest possible value having the same indices

t1 = 2.3
t2 = 5.6
%its is a 2*7*1*10*10*15*8 matrix
p = period_arr(1,:,:,:,:,:,:); % this is of the form p = period_arr(i1, i2, i3, i4, i5, i6, i7);
n = period_arr(2,:,:,:,:,:,:); % this is of the form n = period_arr(i1, i2, i3, i4, i5, i6, i7);
dist_p = abs(p - t1);
[min_dist_p, idx_p] = min(dist_p(:));
dist_n = abs(n - t2);
[min_dist_n, idx_n] = min(dist_n(:));
c_tp = p(idx_p);
c_tn = n(idx_n);
So based on the minimum distance I get the closest value, and it is working fine.
But, I have a problem where I have to get only the closest value where the indices i4 of p = i4 of n and i5 of p = i5 of n. It should regulate the same value for both p and n.
How can I do that? Please help me out. I've been stuck on this problem from 2 days.
For example, I can have
2.6 = period_arr(1,:,:,a,b,:,:)
7.8 = period_arr(2,:,:,a,b,:,:)

6 Comments

Output example
tp = [ 2.2, 2.4, 2.5, 2.6 ]
Looking at this, the closest value is 2.2 or 2.4 w.r.t t1
2.2 = period`_arr(i1, i2, i3, 4, 5, i6, i7)
2.4 = period`_arr(i1, i2, i3, 3, 1, i6, i7)
tn = [ 5.2, 5.4, 7.5, 5.8 ]
Looking at this, the closest value is 5.4 or 5.8 w.r.t t2
5.4 = period`_arr(i1, i2, i3, 1, 2, i6, i7)
5.8 = period`_arr(i1, i2, i3, 4, 5, i6, i7)
so i should choose 2.2 and 5.8 as the close c_tp and c_tn respectively
since the the indices i4 of p = i4 of n and i5 of p = i5 of n. the other i values can take any value
Can someone please help me out in this regard?
  1. do not split the data into separate variables: keep them in vectors/matrices.
  2. use the euclidean distance to find the closest set of points.
Hi Stephen,
1) P and N should be two independent variables. I have to take it that way
2) could you please post some links regarding those
I have checked this yesterday, but this is not the solution that i am looking for.

Sign in to comment.

Answers (0)

Asked:

on 28 May 2020

Commented:

on 29 May 2020

Community Treasure Hunt

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

Start Hunting!