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 Center および File ExchangeFinancial Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by