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
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!