Those are interesting points that I hadn't considered, though you would probably want to be more careful with how you specify tolerances anyway when you work with such large numbers.

I originally wrote the search with nested for loops (I know, I should be shot), but then to "optimize" it, I used ismember and find to make it better. Unfortunately, it slowed it down rather significantly. I was excited to see this code, but it turn out that it does it the same way. Too bad.

savefig
Save *cropped* figures to pdf, eps, png, jpeg, and tiff through Ghostscript.
Author: Peder Axensten

This is a great program. I use it almost every day. It works well 99% of the time. Sometimes, if there is a really complicated plot, it does not export PDF as a vector file. In those cases, I use Matlab's print command to eps and then let Mac OS X convert the eps to pdf. Even eps2pdf command line doesn't do it.

Do you know what makes it fail to export vector images sometimes?

Thanks for this. In our group, a few people have the newer 2010 version of Matlab with a built in netCDF library. This is good for one of my machines that does not have it. A few tweaks to my own codes here and there to use it but it works nicely. I am using it under SUSE.

A relative tolerance can be useful, but as usual for small values (e.g. 1e-20) further problems will occur.

I think it is a more important problem, that your function does not perform what its name advertises: Not the *closest* row is replied, but the first one inside the tolerance. Although a message is displayed, I'd prefer to use another name or algorithm, e.g.:

[d, ind] = min(sum(bsxfun(@minus, full_array, row) .^ 2, 2));
if d > tol, ind = -1; end

Replying the empty matrix could be more intuitive than -1, when no matching row was found.

Those are interesting points that I hadn't considered, though you would probably want to be more careful with how you specify tolerances anyway when you work with such large numbers.

"(min(distance)-tol)<=eps" is a bad comparison: Imagine, that the distances and tolerance has a magnitude of 1e80. Then comparing with EPS is not sufficient - eps(tol) would be smarter.
Instead of calculating the square root of the distances, it would be much more efficient to compare the squared distances with the squared tolerance.
This would reply the row with the smallest distance, not the first one below the tolerance:
[value, found_index] = min(distance - tol)

A relative tolerance can be useful, but as usual for small values (e.g. 1e-20) further problems will occur.
I think it is a more important problem, that your function does not perform what its name advertises: Not the *closest* row is replied, but the first one inside the tolerance. Although a message is displayed, I'd prefer to use another name or algorithm, e.g.:
[d, ind] = min(sum(bsxfun(@minus, full_array, row) .^ 2, 2));
if d > tol, ind = -1; end
Replying the empty matrix could be more intuitive than -1, when no matching row was found.

Comment only

23 Feb 2013

find_closest_row
Find the index of a row within a larger array while allowing for a tolerance

@Jan Simon,
Those are interesting points that I hadn't considered, though you would probably want to be more careful with how you specify tolerances anyway when you work with such large numbers.
Thanks for the feedback

Comment only

23 Feb 2013

find_closest_row
Find the index of a row within a larger array while allowing for a tolerance

"(min(distance)-tol)<=eps" is a bad comparison: Imagine, that the distances and tolerance has a magnitude of 1e80. Then comparing with EPS is not sufficient - eps(tol) would be smarter.
Instead of calculating the square root of the distances, it would be much more efficient to compare the squared distances with the squared tolerance.
This would reply the row with the smallest distance, not the first one below the tolerance:
[value, found_index] = min(distance - tol)

Comment only