How can I get my function that calculates distance between data and user input with sort data and closest data set from file
2 次查看(过去 30 天)
显示 更早的评论
This simple function is able to get data from 'somedata.xlsx' file and takes input from user and computes the distance between them. I am wondering how I can get this function to sort the the computed distance in increasing order, and grab the first 2.
Here is the file data and my input was [2, 5, 7] and the answer is
2.4495
5.3852
4.5826
so aside from computinf I want it to return:
return increasing order
2.4495
4.5826
returned data sets
3 6 9
6 4 5
function x = computedDist(filename, input)
filedata = readmatrix (filename)
x = vecnorm(filedata - input,2,2);
% get computations increasing order
%grab and retuen first in increasing order data sets
end
0 个评论
采纳的回答
Stephen23
2022-5-25
V = [2,5,7];
M = readmatrix('somedata.xlsx')
D = vecnorm(M-V,2,2)
[X,Y] = mink(D,2)
Z = M(Y,:)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!