Cummulative sum between NaN values

2 次查看(过去 30 天)
I have the fllowing Rainfall Data
NaN
0.250000000000000
0
0
0.250000000000000
0
0
0
0.250000000000000
0
0.250000000000000
0
0
0.250000000000000
NaN
0.250000000000000
0
0
0
0.250000000000000
0.250000000000000
NaN
0.250000000000000
0.760000000000000
I would like to find the cummulative Sum between the NaN. It should be:
NaN
0.250000000000000
0.250000000000000
0.250000000000000
0.500000000000000
0.500000000000000
0.500000000000000
0.500000000000000
0.750000000000000
0.750000000000000
1.000000000000000
1.000000000000000
1.000000000000000
1.250000000000000
NaN
0.250000000000000
0.250000000000000
0.250000000000000
0.250000000000000
0.500000000000000
0.500000000000000
NaN
0.250000000000000
0.910000000000000

采纳的回答

Chunru
Chunru 2022-4-6
编辑:Chunru 2022-4-6
The result you gave above seems not correct.
x=[ NaN
0.250000000000000
0
0
0.250000000000000
0
0
0
0.250000000000000
0
0.250000000000000
0
0
0.250000000000000
NaN
0.250000000000000
0
0
0
0.250000000000000
0.250000000000000
NaN
0.250000000000000
0.760000000000000];
idx = find(isnan(x));
y = x;
idx = [0; idx; length(x)+1];
for i=1:length(idx)-1
y(idx(i)+1:idx(i+1)-1) = cumsum(x(idx(i)+1:idx(i+1)-1));
end
disp(y)
NaN 0.2500 0.2500 0.2500 0.5000 0.5000 0.5000 0.5000 0.7500 0.7500 1.0000 1.0000 1.0000 1.2500 NaN 0.2500 0.2500 0.2500 0.2500 0.5000 0.7500 NaN 0.2500 1.0100

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by