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
Which is closest value to 26.601.
26.801 is not the closest value in this array.
Best Answer