Problem aligning data

10 views (last 30 days)
Jens Schaldemose
Jens Schaldemose on 7 May 2012
I'm currently doing my bachelor thesis and I'm having a problem with a code that does not work for me.. I have 248 observations of stock returns and I have 252 index returns. I need to remove the dates and returns from the index where trading days are missing so I will obtain 248 index returns. I have used the following codes, but it does not remove my data like i want it to do:
ds=datesstock; ps1=returnstock; dm=datesindex; m = length(dm); n = length(ds);
if (m > n) ps = zeros(m,1); c = 1; for i=1:m j = find (dm(i)== ds); if (isempty(j)) ps(i) = NaN; else ps(i) = ps1(c); c = c+1; end end else ps = ps1; end
  1 Comment
Jan
Jan on 7 May 2012
1. Please format your code as explained in the "Markup help" link.
2. "It does not remove my data like I wanted" is not helpful to find out, what you want and what you get. We cannot run the posted code and guessing the difference between your intention and the results is impossible.
3. While terms like "observation of stock returns" is surely meaningful for you, it is not for scientist of other fields. For Matlab the meaning of the variables does not matter at all, so it would be more clear if you write: I have a [1 x N] vector of type DOUBLE.
Please edit your original question to add the clarifications. Do neither post them as comment, answer or new thread, because this would be less helpful for the readers of your question. Thanks.

Sign in to comment.

Answers (1)

bym
bym on 7 May 2012
doc intersect()

Categories

Find more on Holidays / Seasons in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!