Filter löschen
Filter löschen

Cummulative sum between NaN values

2 Ansichten (letzte 30 Tage)
Queena Edwards
Queena Edwards am 6 Apr. 2022
Kommentiert: Queena Edwards am 6 Apr. 2022
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

Akzeptierte Antwort

Chunru
Chunru am 6 Apr. 2022
Bearbeitet: Chunru am 6 Apr. 2022
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

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by