Refactor out the commonality into a subroutine where can use the same variable names without clashing with scope --
obj = 10; % global parameter
% range
G2 = f_range_m(1:8:length(timeline_ms),:);
G1 = OrgiRange(1:8:end,:);
Result_R=infoFunc(G1,G2,obj);
% doppler
G2 = f_vel_mps(1:8:length(timeline_ms),:);
G1 = xVelOrgins_g(1:8:end,:);
Result_V=infoFunc(G1,G2,obj);
% angle
G2 = s_angQ15(1:8:length(timeline_ms),:);
G1 = OrgiAngle(1:8:end,:);
Result_A=infoFunc(G1,G2,obj);
function res=infoFunc(G1,G2,obj)
res=nan(size(G1,1),obj);
for ix = 1:obj
dist = abs(bsxfun(@minus,G2,G1(:,ix)));
[~,col] = min(dist,[],2);
res(:,ix) = diag(G2(:,col));
end
Rename the function infoFunc to whatever makes sense and put it in a file of that name on the MATLABPATH so it can be found. Or, if the other code is in a higher-level function rather than a script, it could be a private function within it. Unless the data were to be stored in a different structure, replacing the outer logic with a loop would create more issues than it would solve.