How to insert NaNs on an array based on a condition some other array

9 ビュー (過去 30 日間)
Shambhavi Adhikari
Shambhavi Adhikari 2020 年 7 月 24 日
回答済み: Matt J 2020 年 7 月 27 日
I have an array
A= [210,210,210,220,220,220,240]
B= [210,nan,nan,220,nan,nan,240]
C=[1,2,4,5,7,8,10]
and now i remove NaNs from B
index= find(~isnan(B))
and apply this index to B and C
New
B= [210,220,240]
and new
C=[1,5,10]
and now my condition is if
diff(B)<=10 & diff(C)<=4
, i insert NaNs between these indexes in A
so my final A is:
A= [210,210,210,220,nan,nan,240]
Can you please me do this?
  5 件のコメント
Shambhavi Adhikari
Shambhavi Adhikari 2020 年 7 月 24 日
sorry there should be 2 A is: [210,210,210,220, nan,nan,240]
Jalaj Gambhir
Jalaj Gambhir 2020 年 7 月 27 日
Yeah, but how are you getting indices 5 & 6 to insert nan in array A, based on this condition? "diff(B)<=10 & diff(C)<=4" Please frame your question in a better way.

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2020 年 7 月 27 日
Using group1s from the File Exchange
index = ~isnan(B);
nangroups = group1s(~index);
diffg = find(diff(B(index))<=10 & diff(C(index))<=4);
mask=any( nangroups==diffg(:) , 1)
A(mask)=nan

カテゴリ

Help Center および File ExchangeR Language についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by