I tried a simple vectorized solution of permute and sum of squares approach, but ran into "out of memory" issues:
>> C = dlmread('CoarseTjointMesh.txt','',9,0);
>> C(:,2:4) = C(:,2:4)*1e-3;
>> F = dlmread('matrix.txt','',0,0);
>> B = 3*8*size(C,1)*size(F,1)
B = 13703964384
>> num2sip(B)
ans = 13.704 G
However using a cell array worked without error, and is just as simple:
tmp = num2cell(C(:,2:4),2);
fun = @(v)min(sum((v-F(:,8:10)).^2,2));
[dst,idx] = cellfun(fun,tmp);
out = F(idx,2:7);
Note that the subtraction inside the anonymous function requires scalar dimension expansion, which was introduced in R2016b. For earlier versions replace the subtraction with bsxfun.
Best Answer