how to increase the number of samples in a vector using interpolation
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
i have n number of vectors each having different number of samples. It is required to have the same number of samples in each vector. how can i do this using interpolation. for example vec1= [3 5 2 1]; vec2=[4 5 3 4 3 1 4] ; i required that vec1 and vec2 should be of same length say 10 please help
1 Commento
Stephen23
il 24 Feb 2018
"i have n number of vectors..."
Note that accessing variable names in a loop is slow, complex, buggy, and hard to debug:
Putting these vector into one cell array would mean you could trivially loop over them all using a for loop and indexing, which is simple, intuitive, and very efficient.
Risposta accettata
Stephen23
il 24 Feb 2018
Modificato: Stephen23
il 24 Feb 2018
>> vec1 = [3 5 2 1];
>> vec2 = [4 5 3 4 3 1 4];
>> xo1 = 1:numel(vec1);
>> xo2 = 1:numel(vec2);
>> xi1 = linspace(1,numel(vec1),10);
>> xi2 = linspace(1,numel(vec2),10);
>> interp1(xo1,vec1,xi1)
ans =
3 3.6667 4.3333 5 4 3 2 1.6667 1.3333 1
>> interp1(xo2,vec2,xi2)
ans =
4 4.6667 4.3333 3 3.6667 3.6667 3 1.6667 2 4
"i have n number of vectors ..."
When you put them into one cell array then you can trivially loop over all of them:
C = {[3 5 2 1], [4 5 3 4 3 1 4], ...};
D = cell(size(C));
for k = 1:numel(C)
N = numel(C{k});
xo = 1:N;
xi = linspace(1,N,10);
D{k} = interp1(xo,C{k},xi);
end
2 Commenti
WEEKIAN SOH
il 24 Feb 2018
Dear Stephen Cobeldick, my name is Kian, and I am a fan of your function, num2words(). Absolutely amazing! You had just managed to make our MATLAB software output readable text!!! I'll be following your post closely, and I look forward to learning from you the Master of MATLAB.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!