Merging two matrices by first column values
Ältere Kommentare anzeigen
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 Kommentare
Rose
am 15 Apr. 2014
are the dates in ascending order?
Scott
am 15 Apr. 2014
pietro
am 15 Apr. 2014
Are A and B cell arrays?
Scott
am 15 Apr. 2014
Patrik Ek
am 15 Apr. 2014
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
am 15 Apr. 2014
David Sanchez
am 15 Apr. 2014
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
am 15 Apr. 2014
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
am 15 Apr. 2014
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Time Series Objects finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!