Effacer les filtres
Effacer les filtres

Cummulative sum between NaN values

2 vues (au cours des 30 derniers jours)
Queena Edwards
Queena Edwards le 6 Avr 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

Réponse acceptée

Chunru
Chunru le 6 Avr 2022
Modifié(e) : Chunru le 6 Avr 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

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by