Inserting NaN values between results

3 views (last 30 days)
Queena Edwards
Queena Edwards on 5 Apr 2022
Commented: Walter Roberson on 6 Apr 2022
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

Answers (1)

Walter Roberson
Walter Roberson on 5 Apr 2022
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 Comments
Queena Edwards
Queena Edwards on 5 Apr 2022
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 on 6 Apr 2022
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

Sign in to comment.

Categories

Find more on Numeric Types in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!