Using two vectors to scale a vector
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
ParkerCambridge
il 25 Lug 2019
Risposto: Star Strider
il 25 Lug 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 Commenti
Risposta accettata
Star Strider
il 25 Lug 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!