How to merge two arries with different elements?

1 回表示 (過去 30 日間)
Shenjie Zhou
Shenjie Zhou 2016 年 9 月 15 日
編集済み: Adam 2016 年 9 月 15 日
I am working on two series of observational data. Both of them are acquired at the same location at the same time only with two different sensors. Now due to the unstable observational environment, both of them would have some temporary failure in acquiring data. Now I would like to merge the observation data of these two sensors by time, so I could fill in the data blank over the whole observation period.
For example, the functional time of sensor one is [0,1,2,3,4,6,7,8,11,15,23] (hour of the day), while the sensor two are functional at [2,3,4,5,7,9,10,12,13,14,16,18,20,22]; How should I merge these two time record as one, with several commands?
the expectation on the merged array is [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,23];
I realize the algorithm is simple, but I would like to have some related function in matlab that I can apply on this issue.
Thanks in advance!
Jason
  4 件のコメント
Adam
Adam 2016 年 9 月 15 日
Also what happens if neither sensor picked up a reading at a given time?
Shenjie Zhou
Shenjie Zhou 2016 年 9 月 15 日
Fill up the time record, but put the corresponding readings as NaN.

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

採用された回答

Adam
Adam 2016 年 9 月 15 日
編集済み: Adam 2016 年 9 月 15 日
t1 = [0,1,2,3,4,6,7,8,11,15,23];
r1 = rand( 1, 11 );
t2 = [2,3,4,5,7,9,10,12,13,14,16,18,20,22];
r2 = rand( 1, 14 ) * 100;
rNew = NaN( 2, 24 );
rNew( 1, t1 + 1 ) = r1;
rNew( 2, t2 + 1 ) = r2;
rNew = nanmean( rNew );
should do the job, obviously with your real data values instead of the random data I used.
You can also use
rNew = mean( rNew, 'omitnan' );
if you prefer.
Obviously the time array you can just create as:
tNew = 0:23;
  1 件のコメント
Shenjie Zhou
Shenjie Zhou 2016 年 9 月 15 日
That is brilliant, thanks a lot!

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2016 年 9 月 15 日
If you're using the new timetable datatype introduced in release R2016b to store your data, take a look at the synchronize function. If not, use interp1 to interpolate both signals to a common time basis.
  1 件のコメント
Shenjie Zhou
Shenjie Zhou 2016 年 9 月 15 日
Hi Steven,
Interpolation is also a solution, but one of the sensor has missed records more than the other one, so the interpolation on this sensor readings may introduce some error. I am trying to keep the observational data as original as possible.
Thank you for you comment!

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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by