> Sorry! I screwed up in the posted code, please use the
> following instead:
[quoted text clipped - 39 lines]
> averagemaxtissuedistance = mean(maxtissuedistance)
> averagetissuedistance = mean(tissuedistance)
You could improve the code right away by preallocating your matrices and
using a counter to add to them.
But I'm not quite sure what kind of data structure you're trying to
create here. It looks like for each i/j/k index you want the distance
to the closest vAVGF entry, but only if it is within a certain
threshold. But then you want the average min/max/total distances for
the entire dataset...
Given that the i/j/k index set is evenly spaced and even integer, you
should really reverse the order of your search. Say I'm looking for the
closest integers to (3.2, 4.2, 1.7). Do I really need to loop from
(0,0,0) to (10,10,10) across all 3 dimensions, comparing each, to
realize that my closest is (3,4,2)? Take advantage of that even
spacing.
I realize actually want ALL the i/j/k indices that fall within the
threshold. Fine. You can at least limit your i/j/k search to a 3D
bounding box. In the above example, if the radius is 3, then you might
actually have to calculate the integer indices between:
0.2,1.2,0 to 6.2,7.2,4.7
Don't forget to round inward: (0,2,0) to (6,7,4) That's a MUCH smaller
set of indices to compute actual euclidean distance from.
The downside is you have to store a running minimum and a running
maximum for each i/j/k value. But that's easy. After you compute the
distances (over your smalling bounding box) into a 3D matrix, just take
the min of that whole thing with your running min matrix, and same with
the max.
Does that make sense? Shrinking the number of points you need to
compute is the most powerful way to reduce the runtime. If you can
express more specifically what you are trying to compute off of this,
you might be able to do better.
-Peter