@Werner_E wrote:
You get different lengths for X.CPT and Y.CPT because you obviously specified wrong ranges!

I'm rarely confident enough to opine that something is "obviously" wrong. However, I did notice your comments but left the ranges alone until Yusra came back with her response to your questions.

@YA_10963798 Please, pretty please, can you change your variable names "rows" and "cols" to something like "nrows" and "ncols"? I keep forgetting that you've redefined these functions and spend ages hunting down what I think is an error on my part until I finally (re)notice that rows doesn't mean what I think it does.
I removed the header information from the "nearest pair" array and passed it instead to one of my Table functions, modified for ORIGIN independence.


But I did find one variant of my mega unnesting function that we mentioned in the recent Kinematics thread. The variant was a little too complex for most needs, so I've remodelled it to do basic one-level unnesting. It's just a glorified version of the one I special-to-type function I posted in the kinematics thread, modified for (what I think is) ORIGIN independence (I hate making things origin independent; it makes my brain hurt, and I'm always hunting for missing ORIGINs).
Anyway. Rather than rework something that works (not everybody has my vices!) then, it might be a lot easier to do as we discussed on the recent Kinematics thread = hammer any offending nested arrays into shape by flattening them until they see the light and become matrices. Meet the hammer, suitably modified for ORIGIN independence (I think) ...

Stuart