在Matlab中最小化简单目标的最佳方法 [英] Best way of minimizing simple objective in Matlab
问题描述
在此图像中找到沿x轴的蓝线偏移的最佳方法是什么 使其与红线匹配?结果必须看起来像这样的图像 ).在MATLAB中,有诸如fminunc之类的复杂函数,但是我必须处理一些时间限制,因此我想知道是否还有更有效的方法.
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.
数据来自模拟环境中激光扫描的范围测量.在x轴上,您可以看到每次扫描的方位角(以弧度为单位)与在y轴上以米为单位的测量范围有关.对于红点(参考扫描),轴承确实均匀地隔开.参考扫描始终是这种情况,但当前扫描却没有(蓝点).
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).
红点数据
-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
还有蓝点
-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
推荐答案
好的,这不是最佳"方法,但是如果您不知道描述曲线的正确模型,这是一种方法:
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-')
这篇关于在Matlab中最小化简单目标的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!