Borrar filtros
Borrar filtros

Translate values from plot to another

6 visualizaciones (últimos 30 días)
Willem
Willem el 4 de Feb. de 2013
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 comentarios
Image Analyst
Image Analyst el 4 de Feb. de 2013
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).
Willem
Willem el 12 de Mzo. de 2013
My apologies. This was one of those scenarios where I had too much on my plate and not enough time to just think about it. I got lazy and asked for help when it was pretty simple really. I was thinking there might be some sort of Matlab function specifically designed to match similar datasets. I should have been more specific. As both graphs share the same x axis I just plotted one against the other and then used a best fit. I made this more complicated then it needed to be.

Iniciar sesión para comentar.

Respuestas (1)

Matt Tearle
Matt Tearle el 4 de Feb. de 2013
Editada: Matt Tearle el 4 de Feb. de 2013
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)

Categorías

Más información sobre Two y-axis en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by