Skip to content

Commit

Permalink
Merge pull request #25 from maanikmarathe/maanikmarathe-closest-srcs-…
Browse files Browse the repository at this point in the history
…helper

Add helper function closest_srcs
  • Loading branch information
behinger authored Sep 21, 2023
2 parents fb83d6c + 6580e25 commit d7f0bf9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,22 @@ function convert(eeg, onsets, design;reshape=true)

end


"""
Takes an array of 'm' target coordinate arrays (1-by-3) and a matrix (n-by-3) of all available positions, and returns an array of size 'm' containing the indices of the respective items in 'pos' that are nearest to each of the target coordinates.
"""
function closest_srcs(coords_list, pos)
out = [];
s = size(pos);
dist = zeros(s[1]);
diff = zeros(s[2]);
for coords in coords_list
for i=1:s[1]
for j=1:s[2]
diff[j] = pos[i,j] - coords[j];
end
dist[i] = norm(diff);
end
push!(out,findmin(dist)[2]) #retain only the index of the minimum difference.
end
return out
end

0 comments on commit d7f0bf9

Please sign in to comment.