This is the same statement for 3 times. how to do this with loop. Here, the matrix G1 dimension is 3*10. so in each part i am taking different column.
G2 = f_range_m(1:8:length(timeline_ms),:); %%%% measured range
G1 = OrgiRange(1:8:end,:);
M1 = G1(:,1);
dist11 = abs(bsxfun( @minus,G2,M1));
[~,col1] = min(dist11,[],2);
Result_1 = diag(G2(:,col1));
M2 = G1(:, 2);
dist22 = abs(bsxfun(@minus,G2, M2));
[~,col2] = min(dist22,[],2);
Result_2 = diag(G2(:,col2));
M3 = G1(:, 3);
dist33 = abs(bsxfun(@minus,G2, M3));
[~,col3] = min(dist33,[],2);
Result_3 = diag(G2(:,col3));
I am trying this way. However not getting desired output. Result dimension should be 13*3.
obj = 3;
for ix = 1:obj
M = G1(:,ix);
dist = abs(bsxfun(@minus,G2,M));
[~,col] = min (dist,[],2);
Result = diag(G2(:,col));
end
M1M2M3. If you rewrite the code this way, going to a loop is straight forward. You just replace theM{1}with aM{ix}where ix is your loop iterator. Alternatively if you don't need M after the calculation just useMand overwrite it in each iteration. Do the same fordist,colandResultand you got a solution.