From: Luna Moon on
How to make my code faster? Hate my stupid coding!

Hi all,

Here is my code: here the two matrices are Nx2 dTmp1 and dTmp2.

dTmp1(:, 1) and dTmp2(:, 1) are datestamps.

dTmp1(:, 2) and dTmp2(:, 2) are data.

Basically I want to do the following:

if someone give me a set, either the intersection or union or other
operations of dTmp1(:, 1) and dTmp2(:, 1).

I would like to use that as indices and to get get the corresponding
data points from dTmp1(:,2) and dTmp2(:, 2).

I would liek the fastest appraoch...

Thanks
------------------------

nDates=intersect(dTmp1(:, 1), dTmp2(:, 1));

nDates=nDates(:);

dData1=zeros(size(nDates));
dData2=zeros(size(nDates));

for j=1:length(nDates)

nIdx=find(nDates(j)==dTmp1(:, 1));

dData1(j)=dTmp1(nIdx, 2);

nIdx=find(nDates(j)==dTmp2(:, 1));

dData2(j)=dTmp2(nIdx, 2);

end;