Using two vectors to scale a vector

12 次查看(过去 30 天)
Hi,
I have three vectors of different scale, lets say
x1= (0:0.1:1)';
x2 = (0:1:10)';
x3 = [-0.01;0.99;2.01;2.98;3.99;5.001;5.99;7.021;8.001;8.999;10.11];
If I would like to scale x2 to x1, I can use interp1 function as
scaledx2 = interp1([min(x2),max(x2)],[min(x1),max(x1)],x2);
However, for x3 which is slightly different and has got some random noise on it. If I use the same interp1 function as
scaledx3 = interp1([min(x2),max(x2)],[min(x1),max(x1)],x3)
It understandbly gives me NAN values for the 1st and the last values which is incorrect. So how can I scale x3, based on the scales of x1 and x2?
Many Thanks

采纳的回答

Star Strider
Star Strider 2019-7-25
The NaN values at the ends are because interp1 must extrapolate and needs to be told how to do it.
Try this:
scaledx3 = interp1([min(x2),max(x2)],[min(x1),max(x1)],x3, 'linear','extrap')
I use 'linear' here, although any method will work.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by