finding an closest possible element in an 7 dimensional matrix array
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
Code is as follows
time = period_fun(2,2,1,10,10,15,3) is a 7D matrix with has domensions 2*7*1*10*10*15*8
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
So when hardcode the time = 26.601 and pass it.
I am trying to find the closest value possible in period_arr
%finding the closest element possible to time = 26.601
dist = abs(period_fun - time);
min_dist = min(dist(:));
idx = find(dist == min_dist );
disp(period_arr(idx))
The output comes as 26.601, which is wrong.
My array has a value 26.801 which is closer to 26.601 it is not able to pick that value.
How can i precisely tune it ? so that i can make it more robust for even 0.001 variation
Please help me out
댓글 수: 4
채택된 답변
Ameer Hamza
2020년 4월 18일
A matrix with dimensions [2 7 1 10 10 15 8], will have 168000 elements. The file you shared only have 166379 elements. I cannot create the matrix with a specified dimension. If I suggest a solution, you may still not find that it is not working. However, I have given a solution by padding array with zeros to make its size equal to 168000.
fid = fopen('Mat file.txt');
data = textscan(fid, '%f', 'HeaderLines', 6);
period_arr = data{1};
fclose(fid);
period_arr = padarray(period_arr, 168000 - numel(period_arr), 0, 'post');
period_arr = reshape(period_arr, [2 7 1 10 10 15 8]);
time = 26.601;
dist = abs(period_arr - time);
[min_dist, idx] = min(dist(:));
disp(period_arr(idx))
When I run this code, it get the value
26.602
Which is closest value to 26.601.
26.801 is not the closest value in this array.
추가 답변 (1개)
Image Analyst
2020년 4월 18일
If you have the Statistics and Machine Learning Toolbox, try knnsearch(). I think you can have every point be a new class. It will tell you which point is closest to your query point.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!