how to increase the number of samples in a vector using interpolation

8 ビュー (過去 30 日間)
stud
stud 2018 年 2 月 24 日
編集済み: Stephen23 2018 年 2 月 24 日
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 件のコメント
Stephen23
Stephen23 2018 年 2 月 24 日
"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.

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2018 年 2 月 24 日
編集済み: Stephen23 2018 年 2 月 24 日
>> 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 件のコメント
WEEKIAN SOH
WEEKIAN SOH 2018 年 2 月 24 日
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.
Stephen23
Stephen23 2018 年 2 月 24 日
編集済み: Stephen23 2018 年 2 月 24 日
@WEEKIAN SOH: I am glad you like num2words. If you have the time please add a comment and rating at the bottom of the FEX page, so that you can tell others that you found it useful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by