Using two vectors to scale a vector

12 ビュー (過去 30 日間)
ParkerCambridge
ParkerCambridge 2019 年 7 月 25 日
回答済み: Star Strider 2019 年 7 月 25 日
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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by