Using two vectors to scale a vector
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ParkerCambridge
am 25 Jul. 2019
Beantwortet: Star Strider
am 25 Jul. 2019
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
0 Kommentare
Akzeptierte Antwort
Star Strider
am 25 Jul. 2019
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')
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!