Double the resolution of a vector

10 ビュー (過去 30 日間)
Luis Isaac
Luis Isaac 2016 年 8 月 2 日
編集済み: Azzi Abdelmalek 2016 年 8 月 2 日
Dear
I would like to double the resolution of a vector in an efficient way (i.e. vectorizing) I mean, for example for the vector [0 2 5 10 12] the result is [0 1 2 3.5 5 7.5 10 11 12]
Calculate the new values is easy, for example:
a=[0 2 5 10 12];
b=a(1:length(a)-1)+diff(a)/2;
But I don't know how to insert the new values in the original vector
Many thanks,

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 2 日
編集済み: Azzi Abdelmalek 2016 年 8 月 2 日
a=[0 2 5 10 12]
b=sort([a a(1:end-1)+diff(a)/2])
You can also use interp1 function
a=[0 2 5 10 12]
b=interp1(1:numel(a),A,1:.5:numel(A))
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 2 日
Luis Isaac commented
Many thanks The first solution works in this case but it not satisfactory for me because asume that a vector is in ascending order
But the second way is pefect!!
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 2 日
編集済み: Azzi Abdelmalek 2016 年 8 月 2 日
a=[0 2 5 10 12]
b= a(1:end-1)+diff(a)/2
c=zeros(1,2*numel(a)-1)
c(1:2:end)=a
c(2:2:end)=b

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by