필터 지우기
필터 지우기

creating new vector that is a combination of two interpolated vectors

조회 수: 2 (최근 30일)
Vaultec
Vaultec 2014년 7월 24일
댓글: dpb 2014년 7월 24일
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?

채택된 답변

Star Strider
Star Strider 2014년 7월 24일
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
Star Strider
Star Strider 2014년 7월 24일
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 2014년 7월 24일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

dpb
dpb 2014년 7월 24일
편집: dpb 2014년 7월 24일
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

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by