0

I have 6 cross-sectional time series arrays with varying dates and about 99 assets. I want to create a new array with only common dates from all the six arrays. I tried using the following function which uses "ismember" which works well for 2 arrays, but i am unable to generalize it for n arrays.

idx = ismember(indexchg(:,1),equitychg (:,1))
finalmatrix = [indexchg(idx,1) indexchg(idx,2) equitychg(idx,2:end)]

Can someone suggest a way to generalize this. I am trying to use find function in Matlab to find asset and dates but that i guess will have to run a host of loops to arrange the data. Can anyone suggest an easier way

5
  • Have you tried using the merge method: merge(indexchg, equitychg , otherchgs, .... ,'DateSetMethod','Intersection') Commented Aug 20, 2013 at 9:00
  • idx is indexing indexchg but you also pass it to equitychg in last line, doesn't seem right. Commented Aug 20, 2013 at 9:10
  • the dataset is form of double array so I can't use merge Commented Aug 20, 2013 at 9:32
  • is there a way to convert a double array to a financial time series object Commented Aug 20, 2013 at 10:52
  • If they're not financial time series objects, then I'd suggest you stick with your method and just use a loop. Maybe create a cell array to help you not have to keep typing out each different array name Commented Aug 20, 2013 at 13:19

1 Answer 1

1

Suppose you have sets A, B, C and want to find elements that occur in all of them, you can nest intersections.

It can be done like this:

mySet = intersect(intersect(A,B),C)

If you are a lazy typist, you can also check out the mintersect File Exchange submission that basically does just this. Then it can be done like this:

mySet = mintersect(A,B,C)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.