Borrar filtros
Borrar filtros

creating new vector that is a combination of two interpolated vectors

2 visualizaciones (últimos 30 días)
Currently I have a vector called A [28 56 84 112 140 168 196 224 252 280 308 336 364 392 420 448 476 504 532 560 588 616 644 672 700 728 756 784 812 840 868 896 924] and another called B that is [82.5 127.5,182.5, 230, 277.5, 330, 380, 432.5, 480, 530, 582.5, 632.5, 682.5, 732.5, 830.5, 882.5 930.5, 980, 1032.5, 1080]
How do I go by interpolating the two vectors such that they will be in units of 1 i.e. [28,29,30…924] for A and [83,84, 85…1080] for B then combining them such that the third new vector will only have points that are common in vector A and vector B after interpolation? After which how would i go about adding zeroes to the end of the third new vector such that it will have the same length as another vector C that is 1xN long?

Respuesta aceptada

Star Strider
Star Strider el 24 de Jul. de 2014
You don’t need to interpolate, simply redefine the A and B vectors as vectors with a step of 1, then use the intersect function to get the values in common to both:
A1 = min(round(A)):max(round(A));
B1 = min(round(B)):max(round(B));
C = intersect(A1,B1);
  4 comentarios
Star Strider
Star Strider el 24 de Jul. de 2014
Your interpolated data would be the same as A1 and B1 here, since that is how you defined them. They proceed linearly from minimum to maximum (rounded) with an increment = 1. You can experiment with interp1, but you will see that the result is the same.
dpb
dpb el 24 de Jul. de 2014
NB:
Star's solution--
>> A1 = min(round(A)):max(round(A));
B1 = min(round(B)):max(round(B));
C = intersect(A1,B1);
dpb's...
>> i1=ceil(max(A(1),B(1)));
i2=floor(min(A(end),B(end)));
C1=[i1:i2];
Compare the two...
>> all(C1==C)
ans =
1
>>
Identical. QED--don't need intersect nor even to create the other series; simply find the upper/lower range limits and fill in between.

Iniciar sesión para comentar.

Más respuestas (1)

dpb
dpb el 24 de Jul. de 2014
Editada: dpb el 24 de Jul. de 2014
i1=ceil(max(A(1),B(1)); % greater of the two start values rounded up
i2=floor(min(A(end),B(end))); % end is minimum of last rounded down
C=[i1:i2]; % the values between the bounds, inclusive

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by