Inserting NaN values between results

2 次查看(过去 30 天)
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 中查找有关 Numeric Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by