MATLAB: Gather data from two matrices depending on values shared in first column

accumarraymatrixquotesstock datatimestamptransaction price

This is kinda a follow-up to this question.
I tried using the same method as in the link, but couldn't really figure out a method that worked.
I have two matrices with unique timestamp (in seconds) in the first column. The values are sorted from low to high in both. However, one matrix has more data than the other (about 20000 unique timestamp observations vs 3000).
What i'd like to do is "import" into the smaller matrix the data from the larger matrix that shares the same timestamp.
Can i do this with accumarray again in some way or do i need a loop?

Best Answer

With appending the found values:
match = ismember(LargerMatrix(:, 1), SmallerMatrix(:, 1));
JoinedMatrix = cat(1, SmallerMatrix, LargerMatrix(match, :));
[dummy, Index] = sort(JoinedMatrix(:, 1));
SortedMatrix = JoinedMatrix(Index, :);
Or creating the mean over the values:
[match, loc] = ismember(LargerMatrix(:, 1), SmallerMatrix(:, 1));
SmallerMatrix(loc, 2:end) = (SmallerMatrix(loc, 2:end) + LargerMatrix(match, 2:end)) * 0.5;