Merging two matrices by first column values
Mostrar comentarios más antiguos
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 comentarios
Rose
el 15 de Abr. de 2014
are the dates in ascending order?
Scott
el 15 de Abr. de 2014
pietro
el 15 de Abr. de 2014
Are A and B cell arrays?
Scott
el 15 de Abr. de 2014
Patrik Ek
el 15 de Abr. de 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
el 15 de Abr. de 2014
David Sanchez
el 15 de Abr. de 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
el 15 de Abr. de 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
el 15 de Abr. de 2014
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Time Series Objects en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!