Best way of minimizing simple objective in Matlab

不想你离开。 提交于 2020-01-04 04:14:05

问题


What is the best way of finding the shift along the x-axis for the blue line in this image such that it matches the red line? The result has to look like this image ). In MATLAB there are complex function like fminunc but I have to deal with some time constraints, so I'm wondering if there are more efficient ways.

Edit: The data is coming from range measurements of an laser scan in a simulated environment. On the x-axis you see the bearing of each scan in radians versus the range measured in meters on the y-axis. For the red points (the reference scan) the bearings are indeed evenly spaced out. This is always the case for the reference scan, but not for the current scan (the blue points).

Edit: data for the red points

-1.5708    6.8542
-1.3963    6.9530
-1.2217    7.2137
-1.0472    7.6592
-0.8727    8.3326
-0.6981    9.2984
-0.5236   10.6477
-0.3491   12.5060
-0.1745   15.0092
     0   18.2745
0.1745   22.3368
0.3491   27.1113
0.5236   32.4112
0.6981   38.0010

And for the blue points

-1.3963    7.0092
-1.2217    7.3112
-1.0472    7.8065
-0.8727    8.5420
-0.6981    9.5872
-0.5236   11.0407
-0.3491   13.0360
-0.1745   15.7225
     0   19.1849
0.1745   23.4301
0.3491   28.3466
0.5236   32.4114

回答1:


OK, it's not the "best" way, but it's a way if you don't know the proper model that describes the curve:

% your first plot
figure(1), clf, hold on
plot(red(:,1), red(:,2), 'ro-')
plot(blue(:,1), blue(:,2), 'bo-')

% approximate reference with splines, so it can be evaluated anywhere
ppred = spline(red(:,1),red(:,2));

% minimize the distance between the curves
f = @(x) norm( ppval(ppred, blue(:,1)+x)-blue(:,2) );    
x0 = fminsearch(f, 0);    
blue(:,1) = blue(:,1)+x0;

% pretty close to your second plot
plot(blue(:,1), blue(:,2), 'ko-')



回答2:


Why not just do a grid search? Make a grid of offset possibilities, like delta_x = [0.0001:0.2:0.0001] and then just evaluate your objective function (least squares?) at every place in the offset grid, and choose the one with minimum error. If you are too short on time to use fminfunc then grid search might be an acceptable approximation.



来源:https://stackoverflow.com/questions/12857108/best-way-of-minimizing-simple-objective-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!