Merging two matrices by first column values
显示 更早的评论
I have two matrices (A and B), the first column in each is a date, the second column is a reading (double). The dates in A and B are not contiguous. The result should be a matrix containing both A and B on the dates for which either OR both are relevent.
e.g.
A =
01/01/2014 1.2345
03/01/2014 1.2345
04/01/2014 1.2345
...
B=
02/01/2014 9.8765
03/01/2014 9.8765
04/01/2014 9.8765
...
Merged=
[date] [A] [B]
01/01/2014 1.2345 NaN;
02/01/2014 NaN 9.8765
03/01/2014 1.2345 9.8765
04/01/2014 1.2345 9.8765
I'm not even sure of the proper name of what I'm trying to achieve? Is there one command or a series of commands to do this, as at the moment I am using a script which just loops through each input but this approach will become unsuitable when the input lengths become large.
9 个评论
Rose
2014-4-15
are the dates in ascending order?
Scott
2014-4-15
pietro
2014-4-15
Are A and B cell arrays?
Scott
2014-4-15
Patrik Ek
2014-4-15
Ok now I cannot follow no longer. Do you mean that the date is a string with dates, a string of serial numbers, or a double with serial numbers? You need to give a better explanation.
Scott
2014-4-15
David Sanchez
2014-4-15
The first column of your A and B matrices is in date format or is it the serial date number:
A =
01/01/2014 1.2345
03/01/2014 1.2345
04/01/2014 1.2345
OR:
A =
735600 1.2345
735659 1.2345
735690 1.2345
???
This is key to give a proper answer
Patrik Ek
2014-4-15
Ok but what format do you want? The serial date number or the date string? Both works, except that the date requires a cell
Scott
2014-4-15
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Time Series Objects 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!