Matching matrices by time array

1 visualización (últimos 30 días)
Rasmus Larsen
Rasmus Larsen el 20 de Nov. de 2015
Editada: Rasmus Larsen el 21 de Nov. de 2015
I have two matrices, one with trade prices and one with bid and offers.
They both have the same first column which is time in seconds (starting at 0.00 UTC time).
What i'd like is to create a new matrix where it gathers these two matrices as [time,price,bid,offer] The two matrices aren't the same size and only a few observations share the same timestamp across both matrices.
So if for example only the price matrix has an observation at a given time i just want the bid and offer cells at that row to be zero or empty. And vice versa.
Hope you understand!

Respuesta aceptada

Kirby Fears
Kirby Fears el 20 de Nov. de 2015
Editada: Kirby Fears el 20 de Nov. de 2015
What you're describing is an outer join. Try working with tables in Matlab to make this kind of operation easier.
Here is an example with some random data:
prices = rand(100,2); % Time in col 1, price in col 2
bidask = rand(90,3); % Time in col 1, bid col 2, ask col 3
% Convert from arrays to tables
pTab = array2table(prices,'VariableNames',{'Time','Price'});
baTab = array2table(bidask,'VariableNames',{'Time','Bid','Ask'});
% Merge tables together using Time as key
newTab = outerjoin(pTab,baTab,'Key','Time','MergeKeys',true);
Hope this helps.
  1 comentario
Rasmus Larsen
Rasmus Larsen el 21 de Nov. de 2015
Editada: Rasmus Larsen el 21 de Nov. de 2015
Hi Kirby.
Thanks for your answer, it worked perfectly!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Financial Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by