Hi,
Code is as follows
time = period_arr (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_arr - 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
It's not clear to me what is populating the time array. what do you mean by
"time = period_arr (2,2,1,10,10,15,3) "
but then
"dist = abs(period_arr - time)"
Is "period_arr" an array or a function? if it's an array, then what is time, and what's the meaning of your first line? just that time is one of the values from period_arr?"
and do you mean 26601 or 26.601?
Any algorithm you make should work for a simpler, smaller, complete example. Please provide one where you can tell us exactly what is in every variable you use.
If either time is the 26,601 value, and period_arr is the 7-dimensional array of values you're comparing to 26,601, then the lines you do have should work for finding the closest value. If you're return value is the same as the search value, it must mean that the search value is present exactly in period_arr.
see the example below:
octave:1> A = rand(3,3,2)
A =
ans(:,:,1) =
0.18686 0.87383 0.64496
0.39935 0.53835 0.51712
0.45375 0.13968 0.26310
ans(:,:,2) =
0.210872 0.797234 0.050743
0.755515 0.162288 0.116637
0.424093 0.592979 0.246532
octave:2> dist = abs(A-0.3)
dist =
ans(:,:,1) =
0.113141 0.573830 0.344958
0.099348 0.238347 0.217116
0.153747 0.160324 0.036896
ans(:,:,2) =
0.089128 0.497234 0.249257
0.455515 0.137712 0.183363
0.124093 0.292979 0.053468
octave:3> mindist = min(dist(:))
mindist = 0.036896
octave:4> idx = find(dist == mindist)
idx = 9
octave:5> A(9)
ans = 0.26310