フィルターのクリア

how to change zero in series number

1 回表示 (過去 30 日間)
Trop Trader
Trop Trader 2024 年 1 月 22 日
コメント済み: Trop Trader 2024 年 1 月 22 日
0 ====>2
2 ====>2
3 ====>3
5 ====>5
1 ====>1
6 ====>6
0 ====>3
0 ====>3
3 ====>3
4 ====>4
7 ====>7
2 ====>2
0 ====>6
6 ====>6
2 ====>2
0 2 3 5 1 6 0 0 3 4 7 2 0 6 2
convert in :
2 2 3 5 1 6 3 3 3 4 7 2 6 6 2
rule: I start from the bottom and look for zeros... I assign each zero equal to the NonzeroPrevious value

採用された回答

Matt J
Matt J 2024 年 1 月 22 日
編集済み: Matt J 2024 年 1 月 22 日
y=[0 2 3 5 1 6 0 0 3 4 7 2 0 6 2 ]
y = 1×15
0 2 3 5 1 6 0 0 3 4 7 2 0 6 2
y(y==0)=nan;
out=fillmissing(y,'next')
out = 1×15
2 2 3 5 1 6 3 3 3 4 7 2 6 6 2
  1 件のコメント
Trop Trader
Trop Trader 2024 年 1 月 22 日
yes.it better..thx

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

その他の回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2024 年 1 月 22 日
Assuming the last element is not zero -
in = [0 2 3 5 1 6 0 0 3 4 7 2 0 6 2].';
idx = in==0;
while any(idx)
in(idx) = in([false; idx(1:end-1)]);
idx = in==0;
end
disp(in)
2 2 3 5 1 6 3 3 3 4 7 2 6 6 2

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by