combining different size arrays based on time dimension and compute average for the last column
2 次查看(过去 30 天)
显示 更早的评论
Hello:
I have two disimilar sized arrays, M1 (37988x5) and M2 (37376x5). The first four column shows year,month,day and hour and the last column show the value at each hour. I want to horizontally concatenate these two arrays based on time dimension. But since M2 has some days missing, which is in M1, I want to fill these values with Nan. So resulting matrix I need is 37988x7. The format of resulting array would be:
<Year> <Month> <Day> <hour> <last col of M1> <last col. of M2> <mean of last col. of M1 and M2>
I know I can create a time table array from both M1 and M2 but not sure how to horizontally concatenate two dismilar arrays together and compute average based on the values of M1 and M2. Since M2 doesn't contain some of the days, I want to fill 'nan' for those rows while computing the average.
0 个评论
采纳的回答
Fabio Freschi
2019-9-8
编辑:Fabio Freschi
2019-9-8
find rows in M2 that are present in M1 (assuming that all rows in M2 are present in M1
[~,iRows] = ismember(M2(:,1:4),M1(:,1:4),'rows');
Then preallocate the new M2 matrix
M2new = [M1(:,1:4) NaN(size(M1,1),1)];
Finally add the available M2 values
M2new(iRows,5) = M2(:,5);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!