Linear Interpolation to eleminate zero values

23 ビュー (過去 30 日間)
Bleron Kroni
Bleron Kroni 2020 年 9 月 24 日
コメント済み: YU-CHEN CHANG 2022 年 6 月 6 日
Hello,
I'm trying to do a linear interpolation of vector y.
So where the 0 begins, I want to take the previous value that is 1 and where the 0 end, the next value that is 4 and interpolate.
That for the next section too, From 3 to 2
Can anyone help please
yn = interp1( idx_start,idx_end ,'spline');
y = [1 2 1 0 0 4 2 1 2 3 0 0 0 2 4 2 2 1]
for k = 1:length(y)-1
if y(k)== 0
idx_start = y(k-1)
break
else
while y(k)== 0
k = k+1
if k>0
idx_end = y(k)
break
end
end
end
end

採用された回答

Johannes Hougaard
Johannes Hougaard 2020 年 9 月 24 日
I'm not sure I fully understand your issue, but this may be a solution (or something to point you in the direction)
y = [1 2 1 0 0 4 2 1 2 3 0 0 0 2 4 2 2 1]
x = 1:length(y);
y0 = y(y~=0);
x0 = find(y~=0);
y_int = interp1(x0,y0,x,'linear');
  1 件のコメント
YU-CHEN CHANG
YU-CHEN CHANG 2022 年 6 月 6 日
thanks for your answer
help me in 2022 :)

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by