# Bring two vectors in the same length

2 views (last 30 days)
Manuel on 26 Sep 2016
Answered: Michael Abboud on 28 Sep 2016
Hi MATLAB Experts,
I have the following problem:
I have two data vectors v1 (Length N1=13812) and v2 (Length N2=60002021). I have to bring both vectors in the same length N3 using interpolation bzw. downsampling, with the requirement: 2xN1<N3<N2.
Can somebody help me? My idea was to use: interp, interp1 and downsample to solve to problem. Is that the right approach?
KSSV on 26 Sep 2016
Yes...you can use interp1....

Michael Abboud on 28 Sep 2016
Once you pick a value for N3 within your requirements, you can try something such as the following command, which should work for both interpolating to a larger or smaller length.
>> x1 = 1:N1;
>> v1_N3 = interp1( x1*N3/N2, v1, 1:N3);
The idea is that your original signal “v1” has an implicit corresponding vector “x1” such that each data point lies at (x,y) = (x1,v1). You want to scale your existing vector “x1” such that the values of “v1” lie within [1, N3], but not necessarily on integer values. E.g. your first 3 values of “v1” might land on x = [1, 1.7, 2.4, …]. Then you request values of “v1_N3” at the exact indices of xq = 1:N3.