Bring two vectors in the same length

1 visualización (últimos 30 días)
Manuel
Manuel el 26 de Sept. de 2016
Respondida: Michael Abboud el 28 de Sept. de 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?

Respuestas (1)

Michael Abboud
Michael Abboud el 28 de Sept. de 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.

Community Treasure Hunt

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

Start Hunting!

Translated by