-
Notifications
You must be signed in to change notification settings - Fork 2
/
findClosest.m
30 lines (27 loc) · 1.01 KB
/
findClosest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
% PURPOSE: Find symbol vector from an N-dimensial list of symbol vectors
% that is closest to the given passed in point
% INPUTS:
% point: vector representing measured point
% M_ary_points: matrix listing possible symbol vectors to be searched,
% with each column representing a different symbol vector
%
% OUTPUT:
% closest_symbol_zeroindexed:
% Number of the matching symbol vector (between 0 and M-1) in
% M_ary_points that was closest to the "dim" dimensional point
% represented by the passed in variable point.
%
% Author: Neal Patwari, Feb 2019
function closest_symbol_zeroindexed = findClosest(point,M_ary_points)
dim = length(point);
symbols = size(M_ary_points,2);
dist = zeros(symbols,1);
for i = 1:symbols
accum = 0;
for j = 1:dim
accum = accum + (M_ary_points(j,i) - point(j)).^2;
end
dist(i) = sqrt(accum);
end
[~, ind] = min(dist);
closest_symbol_zeroindexed = ind -1;