필터 지우기
필터 지우기

Inserting NaN values between results

조회 수: 2 (최근 30일)
Queena Edwards
Queena Edwards 2022년 4월 5일
댓글: Walter Roberson 2022년 4월 6일
I have the following cummulative data:
RF_Cumm =
0.510000000000000
0.510000000000000
0.510000000000000
0.510000000000000
0.510000000000000
1.780000000000000
1.780000000000000
1.780000000000000
2.800000000000000
RF_Cumm =
3.300000000000000
RF_Cumm =
1.780000000000000
3.560000000000000
4.070000000000000
4.070000000000000
15.240000000000000
RF_Cumm =
0.250000000000000
0.760000000000000
1.010000000000000
1.010000000000000
1.010000000000000
1.010000000000000
1.010000000000000
1.260000000000000
I would like to insert NaN before and after the different sets of RF_Cumm events to look like:
NaN
0.510000000000000
0.510000000000000
0.510000000000000
0.510000000000000
0.510000000000000
1.780000000000000
1.780000000000000
1.780000000000000
2.800000000000000
NaN
3.300000000000000
NaN
1.780000000000000
3.560000000000000
4.070000000000000
4.070000000000000
15.240000000000000
NaN
0.250000000000000
0.760000000000000
1.010000000000000
1.010000000000000
1.010000000000000
1.010000000000000
1.010000000000000
1.260000000000000

답변 (1개)

Walter Roberson
Walter Roberson 2022년 4월 5일
All_RF_Cumm = [];
for ... whatever looping is appropriate
... stuff
RF_Cumm = whatever is appropriate
if isempty(All_RF_Cumm)
All_RF_Cumm = RF_Cumm;
else
All_RF_Cumm = [All_RF_Cumm; nan; RF_Cumm];
end
... more stuff
end
  댓글 수: 4
Queena Edwards
Queena Edwards 2022년 4월 5일
NaNv = find(isnan(Time)); %Finding Nan in Time Column
Rain([find(isnan(Time))])=NaN; %Changing the numbering of events to NaN in accordance with that from Time column
idx2 = isnan(Rain); %Finding the NaN in the Rain Column of T2
NaNv = [NaNv; size(Rain,1)]; %Last Index (Instead Of Last 'NaN') Is The End Of The Vector
Events = 1:numel(NaNv)-1;
for x = Events
idxrng = NaNv(x)+1:NaNv(x+1)-1; %Index defining the rainfall between NaN
RF_Cumm = cumsum(Rain(idxrng)); %Cumulative Rainfall In Each Event (mm)
end
that's what i used to get RF_Cumm what would be the new loop?
Walter Roberson
Walter Roberson 2022년 4월 6일
NaNv = find(isnan(Time)); %Finding Nan in Time Column
Rain([find(isnan(Time))])=NaN; %Changing the numbering of events to NaN in accordance with that from Time column
idx2 = isnan(Rain); %Finding the NaN in the Rain Column of T2
NaNv = [NaNv; size(Rain,1)]; %Last Index (Instead Of Last 'NaN') Is The End Of The Vector
Events = 1:numel(NaNv)-1;
All_RF_Cumm = [];
for x = Events
idxrng = NaNv(x)+1:NaNv(x+1)-1; %Index defining the rainfall between NaN
RF_Cumm = cumsum(Rain(idxrng)); %Cumulative Rainfall In Each Event (mm)
if isempty(All_RF_Cumm)
all_RF_Cumm = RF_Cumm;
else
All_RF_Cumm = [All_RF_Cumm; nan; RF_Cumm];
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by