필터 지우기
필터 지우기

Cummulative sum between NaN values

조회 수: 2 (최근 30일)
Queena Edwards
Queena Edwards 2022년 4월 6일
댓글: Queena Edwards 2022년 4월 6일
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