Translate values from plot to another
1 次查看(过去 30 天)
显示 更早的评论
I'm looking for the best way to translate values from one plot to another. I have an ocean instrument with a pitot tube like speed sensor. From this sensor I have the raw bits associated with the pressure changes which in turn relate to speed. I have taken a dive and calculated speed from change of depth over time. I've posted an image with the two plots. The speed sensor has a range from 500 to 4000 while the speed calculated from the dive ranges from 0 to 2.5 m/s.
Any ideas on how to translate the speed sensor readings into the corresponding m/s from the plot calculating speed from change of depth?
2 个评论
Image Analyst
2013-2-4
I'm not sure I understand what you mean by "translate values from one plot to another". Do you just want to change the units? If so, what are the units of the plot on the left? Or do you actually want to add/transfer a curve from one plot to another plot, perhaps with two different Y axes like you can do with plotyy()? Or do you want to divide those two plots element-by-element and plot the result in a new plot, or on the same plot? I'm just not clear. Or does translate mean "shift"? Because other than the "language definition" of translate, to me translate means "to move laterally" or, perhaps, to "convert units" (like convert miles per hour into km per hour).
回答(1 个)
Matt Tearle
2013-2-4
编辑:Matt Tearle
2013-2-4
It sounds a bit like you have two measurements that should be the same, except for a scaling factor that you don't know. Is that the idea? If so, you could do a least-squares fit to determine the "best" scaling factor. If y = x*c (for some scalar c you don't know), then you can solve for c using \
c = x\y
(assuming x and y are column vectors). Here's an example:
% Make some fake data
t = linspace(0,1)';
x = sin(3*t.^2).*t + 0.1*rand(size(t));
% y is 12.3*x (ish)
y = 12.3*sin(3*t.^2).*t + 0.3*rand(size(t));
% View
ax = plotyy(t,x,t,y);
% Find the scaling factor via least-squares
c = x\y
% View the results -- the red line should track the green one
hold(ax(2))
plot(ax(2),t,c*x,'r')
You might want to do some pre-processing of your data first, though (trimming the ends, for example)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!