How can I interpolate a vector into a shorter one?

Here is my problem: I have two vectors which I wanna make them same in the length. So my approach was trying to interpolate the long one into the same size of the shorter one.
For example:
A = [1,2,3,4,5]
B = [1,3,5]
I would like to make A to [1.67, 3.33, 5]
Is there a way that MATLAB can help me to interpolate a vector into a shorter one? Or there are other approaches for my problem?
Thanks,

8 Kommentare

Azzi Abdelmalek
Azzi Abdelmalek am 16 Okt. 2013
Bearbeitet: Azzi Abdelmalek am 16 Okt. 2013
What is the relation between your vectors? What are your criterion?
zheng
zheng am 16 Okt. 2013
There are no direct relationships between A and B, and all the data restored in both vectors are coordinates.
sixwwwwww
sixwwwwww am 16 Okt. 2013
Bearbeitet: sixwwwwww am 16 Okt. 2013
In this case you can just replace A with new values because it will not change anything in B because A and B are not related.
Or if they are related to some third parameter then you should also describe that
Ok, but how did you get [ 1.67, 3.33, 5] ?
zheng
zheng am 16 Okt. 2013
Oh, I was just making this up. Trying to give an example for the expected outcome I want.
For this simple case, it is very clear that the relationship in A is linear and easy to compute. So, I just simply divided 5/3 and compute the three point along that linear line.
zheng
zheng am 16 Okt. 2013
@sixwwwwww I don't have new values for A. All the values I have for A are already stored in A and I need my new A vector behave as close as my old A, just shorter.
You can do it using some kind of manipulation. For example you can say that
A = [1.5 3.5 5]
using the logic that new A vector has value which are averaged over two values in old A vector as you can see until you can't make more averaging when it comes to non-even element. You should try to think about such manipulation
zheng
zheng am 16 Okt. 2013
What if I wanna make the shorter one longer? All I need is just a consistency of the two vectors. Is there a way I can use interpolation to do that?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

sixwwwwww
sixwwwwww am 16 Okt. 2013

0 Stimmen

In case that you want to make longer vector shorter you can use some manipulation(For example I call it forward manipulation). Following is a manipulation example
A = [1.5 3.5 5];
count = 1;
for i = 1:length(A)
if i ~= length(A)
A_new(count) = A(i) * 2 - 2 * i;
A_new(count + 1) = A(i) * 2 - A_new(count);
count = count + 2;
else
A_new(count) = A(i);
end
end
And vice versa if you want to make a longer vector shorter you can do some manipulation.(For example I call it backward manipulation). Following is a manipulation example
A = 1:5;
count = 1;
for i = 1:2:length(A)
if i ~= length(A)
A_new(count) = (A(i) + A(i + 1)) / 2;
count = count + 1;
else
A_new(count) = A(i);
end
end
I hope it helps. Good luck!

Kategorien

Mehr zu Interpolation finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 16 Okt. 2013

Beantwortet:

am 16 Okt. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by